JS实现边栏弹出动画

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JS实现边栏弹出动画</title>
  <style type="text/css">
  *{margin:0;padding:0;}
  #box{width:200px;height:200px;background-color:#ccc;position:absolute;left:-200px;top:500px;}
  #share{display:block;font-size:16px;line-height:30px;font-family:微软雅黑;text-align:center;width:24px;height:60px;background-color:orange;position:absolute;left:200px;top:70px;}
  </style>
  <script type="text/javascript">
    window.onload=function(){
      var box=document.getElementById("box");
      box.onmouseover = function(){
        move(10)
      };
      box.onmouseout = function(){
        move(-10)
      };
    }

    var timer;

    function move(spd){
      clearInterval(timer);
      var box = document.getElementById('box');
      timer = setInterval(function(){
        console.log(box.offsetLeft);
        if(box.offsetLeft == -100+10*spd){
          clearInterval(timer);
        }else{
          box.style.left=box.offsetLeft+spd+'px';
        }
      },30);
    }
  </script>
</head>
<body>
  <div id="box" style=""><span id='share'>分享</span></div>
</body>
</html>

遇到的问题及注意事项:

1、offset属性的值是数字,没有‘px’单位。

2、element.style只能获取内联式CSS的属性及用element.style.*=‘ ’设置的属性。非内联式CSS的属性使用obj.currentStyle[attr]方法(ie)或者getComputedStyle(obj,false)[attr]方法(ff)获取。

转载于:https://www.cnblogs.com/oliverliu/p/6855766.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很多博客都有live2D的萌萌哒看板娘,手痒,所以整理了一套HTML5可以用的,注释换一下就可以用啦,最好是放到线上服务器上使用。 L2Dwidget.init({ "model": { //萌娘 jsonPath: "model/live2d-shizuku/assets/shizuku.model.json", //短发女生 //jsonPath: "model/live2d-epsilon2_1/assets/Epsilon2.1.model.json", //双马尾女仆 // jsonPath: "model/live2d-haru_1/assets/haru01.model.json", //双马尾学生装 // jsonPath: "model/live2d-haru_2/assets/haru02.model.json", //小可爱(男) // jsonPath: "model/live2d-haruto/assets/haruto.model.json", //小可爱(女) // jsonPath: "model/live2d-koharu/assets/koharu.model.json", //傲娇学生装女 // jsonPath: "model/live2d-hibiki/assets/hibiki.model.json", //红衣长发女生 // jsonPath: "model/live2d-izumi/assets/izumi.model.json", //黄发制服可爱女生 // jsonPath: "model/live2d-z16/assets/z16.model.json", //黄发女生 // jsonPath: "model/live2d-unitychan/assets/unitychan.model.json", //可爱白猫 // jsonPath: "model/live2d-tororo/assets/tororo.model.json", //可爱黑猫 // jsonPath: "model/live2d-hijiki/assets/hijiki.model.json", //初音未来 // jsonPath: "model/live2d-miku/assets/miku.model.json", //小帅哥 //jsonPath: "model/live2d-chitose/assets/chitose.model.json", //持剑绿衣剑士 // jsonPath: "model/live2d-gf/assets/Gantzert_Felixander.model.json", //科技感短发小女孩 // jsonPath: "model/live2d-ni-j/assets/ni-j.model.json", //狐妖 // jsonPath: "model/live2d-nico/assets/nico.model.json", //绿发女生 // jsonPath: "model/live2d-tsumiki/assets/tsumiki.model.json", "scale": 1 }, "display": { "superSample": 2, "position": "top", "width": 150, "height": 300, "hOffset": 0, "v
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值