精慕门4072777
2018-06-08 13:38
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>鼠标移入</title> <style> body,div,span{ margin: 0; padding: 0; } #div1{ width: 200px; height: 200px; background-color: red; position: relative; left: -200px; } #div1 span{ width: 40px; line-height: 100px; background-color: #336699; color: #ffffff; position: absolute; left: 200px; top: 50px; } </style> </head> <body> <div id="div1"><span id="share">分享</span></div> <script> window.onload=function(){ var moveDiv=document.getElementById("div1"); moveDiv.mouseover=function(){ startMove(); } }; function startMove() { var moveDiv=document.getElementById("div1"); setInterval(function () { moveDiv.style.left=moveDiv.offsetLeft+10+'px'; },30) } </script> </body> </html>
已解决
JS动画效果
113925 学习 · 1443 问题
相似问题