深呼吸_0
2015-09-02 22:29
<!DOCTYPE HTML>
<html>
<head>
<title>JS动画</title>
<meta charset="UTF-8">
<script type="text/javascript">
window.onload = function(){
var share = document.getElementById("div1");
share.onmouseover = function(){
Move();
}
}
var timer=null;
function Move(){
clearInterval(timer);
var share = document.getElementById("div1");
var timer = setInterval(function(){
if (share.offsetLeft ==0 ){
clearInterval(timer);//让整个div1显示完毕后停止向右移动
}else{
share.style.left = share.offsetLeft+10+'px';
}
},30);
}
</script>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
.div1{
width: 300px;
height: 300px;
background-color: #F66;
position: relative;
left: -300px;
}
.div1 span{
width: 50px;
height: 60px;
background-color: blue;
position: absolute;
left: 300px;
top: 120px;
line-height: 60px;
color: #fff;
}
</style>
</head>
<body>
<div>
<span>share</span>
</div>
</body>
</html>
谢谢!我太粗心了!
<div> <span>share</span> </div>
你查找的是id="div1", 添加的式样是class="div1",而在你的div中,这二个你都没写。怎么会有效果
JS动画效果
113925 学习 · 1443 问题
相似问题