Pen Settings

HTML

CSS

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

JavaScript

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

Behavior

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.

HTML

            
              <!-- example6 多物体同时运动 -->
    <div class="example" id="example6">
        <p>多物体同时运动</p>
        <div id="div6">
            <ul>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ul>
        </div>
    </div>
            
          
!

CSS

            
               * {
   margin: 0;
   padding: 0;
 }
 
 #div6 li {
   border: 2px solid black;
   list-style: none;
   position: relative;
   background-color: yellow;
   width: 150px;
   height: 50px;
   margin-bottom: 10px;
   opacity: 1;
 }
            
          
!

JS

            
              window.onload = function() {
  var oDiv6 = document.getElementById('div6');
  var oLiList6 = oDiv6.getElementsByTagName('li');

  var json = {'width':200,'height':150,'opacity':20};
  var json_r = {'opacity':100,'height':50,'width':150,};
  for (var i = 0; i < oLiList6.length; i++) {
    oLiList6[i].onmouseover = function(){
      startAnimate(this,json);
    }
    oLiList6[i].onmouseout = function(){
      startAnimate(this,json_r);
    }
  }
};

var timer,oAttr;
function startAnimate(obj, json, fn) {
  clearInterval(obj.timer);
  // 简单的深拷贝一份 json 数据
  var jsonTmp = JSON.parse(JSON.stringify(json));
  obj.timer = setInterval(function() {
    // 添加不同的动画效果 attr 即每个属性,json[attr] 即属性值
    for (var attr in json) {
    // 判断属性是否为透明度,若为透明度不需要进行字符串转型

    if (attr == 'opacity') {
      // 此处未考虑 IE9 之前的兼容
      oAttr = getStyle(obj,attr) * 100;
    } else {
      oAttr = parseInt(getStyle(obj, attr));
    }
    var speed = (json[attr] - oAttr) * 0.1;
    speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
    if (json[attr] == oAttr) {
      delete jsonTmp[attr];
      var jsonLenght = 0;
      for (var attr in jsonTmp) {
        jsonLenght++;
      }
      if (jsonLenght == 0) {
        clearInterval(obj.timer);
        if (fn) fn();
      }
    } else {
      // 如果属性为透明度,需要和其他属性区别
      if (attr == 'opacity') {
        obj.style.opacity = (oAttr + speed)/100;
      } else {
        obj.style[attr] = oAttr + speed + 'px';
      }
    }
  }
}, 30);
}

function getStyle(obj, attr) {
  if (obj.currentStyle) {
    // IE 浏览器
    return obj.currentStyle[attr];
  } else {
    // Firefox、Chrome
    return getComputedStyle(obj, false)[attr];
  }
}
            
          
!
999px

Console