還是沒(méi)有效果?用的firfox.不知道為什么?
<!DOCTYPE HTML>
<html>
<head>
?? ?<title>JS動(dòng)畫(huà)</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);//讓整個(gè)div1顯示完畢后停止向右移動(dòng)
?? ??? ??? ??? ?}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>
2015-09-04
謝謝!我太粗心了!
2015-09-04
你查找的是id="div1", 添加的式樣是class="div1",而在你的div中,這二個(gè)你都沒(méi)寫(xiě)。怎么會(huì)有效果