<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#div1{
width: 150px;
height: 200px;
background: red;
position: absolute;
left: -150px;
}
#div1 span {
position: absolute;
width: 20px;
height: 60px;
line-height: 20px;
background: yellow;
right: -20px;
top: 70px;
}
</style>
<script>
window.onload=function (ev) {
var oDiv=document.getElementById("div1");
oDiv.onmouseover=function (ev2) {
starMove(0);
};
oDiv.onmouseout=function (ev2) {
starMove(-150);
};
};
var timer=null;
function starMove(iTarget) {
var oDiv=document.getElementById("div1");
clearInterval(timer);
timer=setInterval(function () {
var speed=0;
if(oDiv.offsetLeft>iTarget){
speed=-10;
}
else {
speed=10
}
if (oDiv.offsetLeft==iTarget){
clearInterval(timer);
}
else {
oDiv.style.left=oDiv.offsetLeft+speed+'px';
}
},30)
}
</script>
</head>
<body>
<div id="div1">
<span id="span">分享</span>
</div>
</body>
</html>
JavaScript运动--分享到侧边栏
最新推荐文章于 2022-03-23 00:20:58 发布