源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

javascript动画之圆形运动,环绕鼠标运动作小球

  • 时间:2020-10-10 22:20 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:javascript动画之圆形运动,环绕鼠标运动作小球
代码如下:
[u]复制代码[/u] 代码如下:
<script type="text/javascript"> var ball; var mouseX = 100; var mouseY = 100; var angle = 0; var radius = 50; function run(){ if(ball === undefined){ ball = document.createElement("span"); ball.style.position = "absolute"; ball.style.color = "#FF0000"; ball.style.zIndex = 999999999; ball.innerHTML = "●"; document.body.appendChild(ball); } ball.style["left"] = mouseX+(Math.cos(angle)*radius) + "px"; ball.style["top"] = mouseY+(Math.sin(angle)*radius) + "px"; angle+=0.1; } function MousePos(e) { e = e || window.event; var x,y; if(!document.all){ x = e.pageX; y = e.pageY; } else{ x = event.clientX + document.documentElement.scrollLeft; y = event.clientY + document.documentElement.scrollTop; } return {x:x,y:y}; } function setXY(e) { e = e || window.event; var pos = MousePos(e); mouseX = pos.x; mouseY = pos.y; } window.onload = function(){ setInterval(run,20); document.documentElement.onmousemove = function(e){ e = e || window.event; setXY(e); }; } </script>
作者: cnblogs airy
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部