Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import or require. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <!-- example1 - 简单的运动 -->
<div class="example" id="example1">
  <div id="div1">
    <span>分 享</span>
              * {
    margin: 0;
    padding: 0;
#div1 {
    background-color: red;
    width: 200px;
    height: 200px;
    position: relative;
    left: -210px;
    border: 10px solid black;
#div1 span {
    background-color: blue;
    position: absolute;
    left: 200px;
    top: 50%;
    width: 15px;
    font-size: 15px;
    padding: 5px 2px;
              // 加载完页面执行函数
window.onload = function() {
  // 1、首先获取要运动的元素
  var oDiv1 = document.getElementById('div1');
  // 2、添加鼠标移入事件
  oDiv1.onmouseover = function() {
    // this 即元素本身,iTarget 为动画属性的最终值
    startAnimate(this, 0);
  // 3、添加鼠标移出事件
  oDiv1.onmouseout = function() {
    // this 即元素本身,iTarget 为动画属性的最终值
    startAnimate(this, -210);

var timer; // 声明定时器
// 3、创建动画函数
function startAnimate(obj, iTarget) {
  // 9、当鼠标再次移入时清除上次的定时器,否则定时器会一直叠加
  // 4、设定定时器
  timer = setInterval(function() {
    // 5、通过自定义函数返回元素当前的 left 值,若传回的值为字符串需要转型
    var oleft = parseInt(getStyle(obj, 'left'));
    // 6、设定动画的运动速度并通过要改变的属性值与当前属性值的“位置”关系来判断方向
    var speed = oleft <= iTarget ? 10 : -10;
    // 8、若完成动画效果清除定时器
    if (iTarget == oleft) {
    } else {
      // 7、改变元素的属性值 = oleft + speed + 'px';
  }, 30);

// 传回属性值
function getStyle(obj, attr) {
  if (obj.currentStyle) {
    // IE 浏览器
    return obj.currentStyle[attr];
  } else {
    // Firefox、Chrome
    return getComputedStyle(obj, false)[attr];