Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

HTML

              
                <h4>点击盒子触发</h4>
<div id="box"></div>
<script type="text/javascript">
  var box = document.querySelector("#box");
  //第一个问题 opacity
  //第二个问题 多个属性的写法 需要传入对象 move(box,{"width":300,"height":200},130,1500)
  box.onclick = function(){
    move(box,"opacity",100,1500);
    move(box,"left",300,1500);
  }

  function move(obj,attr,target,time){
    //如果没写默认值 默认就是0 不然在IE出问题
    if(attr=="opacity"){
      var curr = getStyle(obj,attr)*100;//把opacity的值化成整数 好计算
    }else {
      //有单位px parseInt去单位
      var curr = parseInt(getStyle(obj,attr))||0;
    }
    var end = target;
    var sTime = new Date();//开始时间T0
    //开始变换了
    var timer = setInterval(function(){
      var nTime = new Date();//当前时间Tt
      //St = (Tt-T0)/Time*(S-S0)+S0
      //(nTime-sTime)/time 比例最多为1
      var prop = (nTime-sTime)/time; 
      if(prop >=1){
        prop = 1;
        clearInterval(timer);
      }
      if(attr=="opacity"){
        var s = prop*(end-curr)+curr;
        //兼容IE 记得在样式中写上 否则会不生效 IE透明度是filter下的属性
        obj.style.filter = "alpha(opacity="+s+")";
        obj.style[attr] = s/100;
      }else{
        var s = prop*(end-curr)+curr;
        obj.style[attr] = s+"px";
      }

    },13);
  }
  function getStyle(obj,attr){
    return getComputedStyle(obj)[attr]?getComputedStyle(obj)[attr]:obj.currentStyle[attr];
  }


         </script>
              
            
!

CSS

              
                #box {
  position: relative;
  width: 100px;
  height: 100px;
  background: red;
  opacity: 0.5;
  filter:alpha(opcity=20);/*兼容IE*/
}
              
            
!

JS

              
                
              
            
!
999px

Console