js笔记----(运动)分享 隐藏/显示
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <style> body, div { padding:0px; margin:0px; } #box{ height:300px; width:200px; background-color:#ccc; position:absolute;left:-200px; margin-top:200px;border:1px solid #ffd800; border-radius:6px;} #box span{ height:85px; width:40px; position:absolute;left:200px; top:103px; line-height:40px; font-size:20px; background-color:yellow; font-weight:bold; text-align:center; border-radius:6px; border:1px solid #ffd800;} </style> <script type="text/javascript"> window.onload = function () { var oDiv = document.getElementById(‘box‘); oDiv.onmouseover = function () { StarMove(0); } oDiv.onmouseout = function () { StarMove(-200); } } var timer = null; function StarMove(Targer) { var iSpeed = 0; var oDiv = document.getElementById(‘box‘); clearInterval(timer); if (oDiv.offsetLeft < Targer) { iSpeed = 10; } else { iSpeed = -10; } timer = setInterval(function () { if (oDiv.offsetLeft == Targer) { clearInterval(timer); } else { oDiv.style.left = oDiv.offsetLeft + iSpeed + ‘px‘; } }, 30); } </script> </head> <body> <div id="box"> <span>分享</span> </div> </body> </html>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。