名字只是个代号丶
2016-08-02 19:27
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>滑出导航栏</title> <style> body,div,span{ margin: 0; padding: 0; } #div1{ width: 200px; height: 200px; background: red; position: relative; left:-200px; top:200px; } #div1 span{ width: 20px; height: 50px; background: blue; position: absolute; left: 200px; top:75px; } </style> <script> window.onload=function(){ var v=document.getELementById("div1"); v.onmouseover=function(){ star(); v.onmouseout=function(){ star1(); } } } var timer=null; function star(){ clearInterval(timer); var v=document.getELementById("div1"); timer=setInterval(function(){ if(v.offsetLeft==0){ clearInterval(timer); } else{ v.style.left=v.offsetLeft+10+"px"; } },30) } function star1(){ clearInterval(timer); var v=document.getELementById("div1"); timer=setInterval(function(){ if(v.offsetLeft==-200){ clearInterval(timer); } else{ v.style.left=v.offsetLeft-10+"px"; } },30) } </script> <body> <div id="div1"> <span id="share">分享</span> </div> </body> </html>
两个错误
1.
window.onload=function(){
var v =document.getElementById('div1');
v.onmouseover=function(){
star();
}
v.onmouseout=function(){
star1()
}
}
括号问题
2.
var v =document.getElementById('div1');
中的是getElementByld()不是getELementByld();
l不是L
首先32,43,55行的document.getElementById(),有问题是ElementById(),L不要大写还有第34行star();后面少个中括号,38行的中括号去掉,这是两个事件。
是你的document.getEL(这里错了。)ementById("div1");
应该是document.getElementById("div1");
L 大小写的问题。 仔细啊。
推荐你用chrome浏览器。它的检查功能很棒。
加油!
JS动画效果
113923 学习 · 1443 问题
相似问题