为了账号安全,请及时绑定邮箱和手机立即绑定

我希望鼠标移入时div变高,代码哪里写错了?鼠标移入没反应, 麻烦看一下

我希望鼠标移入时div变高,代码哪里写错了?鼠标移入没反应, 麻烦看一下

杨念 2017-03-29 16:43:44
<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title>    <style> div {            width: 100px; height: 100px; background-color:pink; margin: 10px; float: left; border: 10px solid #000; }    </style>    <script> window.onload=function()       {            var div1=document.getElementById("div1");//            var div2=document.getElementById("div2"); div1.onmouseover=function ()                {                    yundong(this,500); }            div1.onmouseout=function ()                {                    yundong(this,100); }            }        function getStyle(obj,name)        {            if(obj.currentStyle)            {                return obj.currentStyle[name]            }            else {                return getComputedStyle(obj,false)[name]; }        }        function yundong(obj,mubiao)        {            clearInterval(obj.timer); obj.timer=setInterval(function()                {                 var cur=parseInt(obj.getStyle(obj,"height"));                  sudu=(mubiao-cur/6);                  sudu=sudu>0?Math.ceil(sudu):Math.floor(sudu);                 if(cur==mubiao)                    {                        clearInterval(obj.timer)                    }                    else                    {                        obj.style.height=cur+sudu+"px";                    }                },30)        }    </script></head><body><div id="div1">变高</div><div id="div2">变宽</div></body></html>
查看完整描述

1 回答

?
杨念

TA贡献2条经验 获得超0个赞

问题已解决,var cur=parseInt(obj.getStyle(obj,"height")); 这一行写错了....

查看完整回答
反对 回复 2017-03-29
  • 1 回答
  • 0 关注
  • 1207 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信