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.

              <!-- example3 多物体运动 -->
<div class="example" id="example3">
  <div id="div3">
              * {
  margin: 0;
  padding: 0;

#div3 li {
  border: 2px solid black;
  list-style: none;
  position: relative;
  background-color: red;
  width: 150px;
  height: 50px;
  margin-bottom: 10px;
  filter: alpha(opacity: 100);
  opacity: 1;
              // 加载完页面执行函数
window.onload = function() {
  // 1、首先获取要运动的元素
  var oDiv3 = document.getElementById('div3');
  var liList3 = oDiv3.getElementsByTagName('li');
  // 2、循环 li 元素添加鼠标事件
  for (var i = 0; i < liList3.length; i++) {
    liList3[i].onmouseover = function() {
      // 这里需要传入 this 作为对象,因为 li 元素已经循环完毕,传入 liList[i] 会导致无法确定目标对象。
      startAnimate(this, 300);
    liList3[i].onmouseout = function() {
      startAnimate(this, 150);

var timer; // 声明定时器
// 3、创建动画函数
function startAnimate(obj, iTarget) {
  // 9、当鼠标再次移入时清除上次的定时器,否则定时器会一直叠加
  // 4、设定定时器
  obj.timer = setInterval(function() {
    // 5、通过自定义函数返回元素当前的 width 值,若传回的值为字符串需要转型
    var oWidth = parseInt(getStyle(obj, 'width'));
    // 6、避免动画速度过快,我们可以降低变化
    var speed = (iTarget - oWidth) * 0.1;
    // 7、因为 speed 减速后不为整数,并且会有精度丢失的情况,因此需要通过 Math 函数来取整动画速度。
    // 当速度大于 0 时向上取整,避免速度取整为 0 造成无运动;反之向下取整,避免速度取整为 0 造成无运动。
    speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
    // 8、若完成动画效果清除定时器
    if (iTarget == oWidth) {
    } else {
      // 7、改变元素的属性值 = oWidth + speed + 'px';
  }, 30);

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