zoukankan      html  css  js  c++  java
  • 一个挺漂亮的鼠标跟随效果

    1. <html> 
    2. <head> 
    3. <title>follow mouse</title> 
    4. <style type="text/css"> 
    5. html { 
    6. overflow: hidden; 
    7. body { 
    8. position: absolute; 
    9. height: 100%; 
    10.  100%; 
    11. margin:0; 
    12. padding:0; 
    13. #screen { 
    14. background:#000; 
    15. position: absolute; 
    16.  100%; 
    17. height: 100%; 
    18. #screen span { 
    19. background: #fff; 
    20. font-size: 0; 
    21. overflow: hidden; 
    22.  2px; 
    23. height: 2px; 
    24. </style> 
    25.   <script type="text/javascript">  
    26. var Follow = function () { 
    27. var $ = function (i) {return document.getElementById(i)}, 
    28. addEvent = function (o, e, f) {o.addEventListener ? o.addEventListener(e, f, false) : o.attachEvent('on'+e, function(){f.call(o)})}, 
    29. OBJ = [], sp, rs, N = 0, m; 
    30. var init = function (id, config) { 
    31. this.config = config || {}; 
    32. this.obj = $(id); 
    33. sp = this.config.speed || 4; 
    34. rs = this.config.animR || 1; 
    35. m = {x: $(id).offsetWidth * .5, y: $(id).offsetHeight * .5}; 
    36. this.setXY(); 
    37. this.start(); 
    38. init.prototype = { 
    39. setXY : function () { 
    40. var _this = this; 
    41. addEvent(this.obj, 'mousemove', function (e) { 
    42. ee = e || window.event; 
    43. m.x = e.clientX; 
    44. m.y = e.clientY; 
    45. }) 
    46. }, 
    47. start : function () { 
    48. var k = 180 / Math.PI, OO, o, _this = this, fn = this.config.fn; 
    49. OBJ[N++] = OO = new CObj(null, 0, 0); 
    50. for(var i=0;i<360;i+=20){ 
    51. var O = OO
    52. for(var j=10; j<35; j+=1){ 
    53. var x = fn(i, j).x, 
    54. y = fn(i, j).y; 
    55. OBJ[N++] = o = new CObj(O , x, y); 
    56. O = o
    57. setInterval(function() { 
    58. for (var i = 0; i < N; i++) OBJ[i].run(); 
    59. }, 16); 
    60. var CObj = function (p, cx, cy) { 
    61. var obj = document.createElement("span"); 
    62. this.css = obj.style; 
    63. this.css.position = "absolute"
    64. this.css.left = "-1000px"
    65. this.css.zIndex = 1000 - N; 
    66. document.getElementById("screen").appendChild(obj); 
    67. this.ddx = 0
    68. this.ddy = 0
    69. this.PX = 0
    70. this.PY = 0
    71. this.x = 0
    72. this.y = 0
    73. this.x0 = 0; 
    74. this.y0 = 0; 
    75. this.cx = cx; 
    76. this.cy = cy; 
    77. this.parent = p; 
    78. CObj.prototype.run = function () { 
    79. if (!this.parent) { 
    80. this.x0 = m.x; 
    81. this.y0 = m.y; 
    82. } else { 
    83. thisthis.x0 = this.parent.x; 
    84. thisthis.y0 = this.parent.y; 
    85. thisthis.x = this.PX += (this.ddx += ((this.x0 - this.PX - this.ddx) + this.cx) / rs) / sp; 
    86. thisthis.y = this.PY += (this.ddy += ((this.y0 - this.PY - this.ddy) + this.cy) / rs) / sp; 
    87. this.css.left = Math.round(this.x) + 'px'; 
    88. this.css.top = Math.round(this.y) + 'px'; 
    89. return init; 
    90. }(); 
    91. </script></head> 
    92. <body> 
    93. <div id="screen"></div> 
    94. <script type="text/javascript"> 
    95. new Follow('screen', {speed: 4, 
    96. animR : 2, 
    97. fn : function (i, j) { 
    98. return { 
    99. x : j/4*Math.cos(i), 
    100. y : j/4*Math.sin(i) 
    101. }}) 
    102. </script></body> 
    103. </html> 

  • 相关阅读:
    poj2774
    GDOI2012 字符串
    poj3261
    poj1743
    bzoj 2565 manacher
    归档-ios
    学习
    ViewPager动态加载、删除页面
    android:ScrollView嵌套ListView的问题
    Android学习笔记进阶之在图片上涂鸦(能清屏)
  • 原文地址:https://www.cnblogs.com/umgsai/p/3908185.html
Copyright © 2011-2022 走看看