杜小洋
2015-07-22 11:48
没有源代码吗,求代码包 ?
var speed=pos>=0?10:-10;这句话是什么意思?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{
margin:0;
padding: 0;
}
div{
width: 200px;
height: 200px;
background: red;
position: relative;
left:-200px;
}
span{
position: relative;
left: 200px;
top: 75px;
background: rebeccapurple;
width: 20px;
height: 50;
display: inline-block;
}
</style>
</head>
<body>
<div id="test">
<span id="share">分享</span>
</div>
<script type="text/javascript">
var divDom = document.getElementById('test');
var timer = null;
divDom.onmouseover=function () {
startMove(0);
}
divDom.onmouseout=function () {
startMove(-200);
}
function startMove (pos) {
clearInterval(timer);
timer = setInterval(function () {
var posLeft = divDom.offsetLeft;
var speed=pos>=0?10:-10;
if(pos==posLeft){
clearInterval(timer);
}else{
divDom.style.left = posLeft+speed+"px";
}
},30);
}
</script>
</body>
</html>
JS动画效果
113925 学习 · 1443 问题
相似问题