温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

js运动框架之侧边框

发布时间:2020-08-11 02:22:04 来源:网络 阅读:358 作者:水滴的历程 栏目:软件技术
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
#div1 {width:150px;height:200px;background:blue;left:-150px;top:100px;position:absolute;}
#div1 span{width:25px;height:50px;position:absolute;left:150px;top:75px;background:yellow;line-height:25x;}
</style>
<script>
window. ()
{
var oDiv=document.getElementById('div1');
oDiv. ()
{
startMove(0);
};
oDiv. ()
{
startMove(-150);
};
};

var timer=null;

function startMove(n1)
{
var oDiv=document.getElementById('div1');
clearInterval(timer);
timer=setInterval(function ()
{
var speed=0;
//判断变框所处位置相对于目标位置,从而赋值速度大小
if(oDiv.offsetLeft>n1)
{
speed=-10;
}
else
{
speed=10;
}
if(oDiv.offsetLeft==n1)
{
clearInterval(timer);
}
else
{
oDiv.style.left=oDiv.offsetLeft+speed+'px';
}
},30);
};

</script>
</head>

<body>
<div id="div1">
<span>分享</span>
</div>
</body>
</html>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI