zoukankan      html  css  js  c++  java
  • 鼠标线状移动特效

     1 <html>
     2 <head>
     3 
     4 <body>
     5 
     6 
     7 <h1 align="center">HelloWord!</h1>
     8 <script>
     9 
    10     !function () {
    11 
    12         function n(n, e, t) {
    13 
    14             return n.getAttribute(e) || t
    15 
    16         }
    17 
    18         function e(n) {
    19 
    20             return document.getElementsByTagName(n)
    21 
    22         }
    23 
    24         function t() {
    25 
    26             var t = e("script"), o = t.length, i = t[o - 1];
    27 
    28             return {
    29 
    30                 l: o, z: n(i, "zIndex", -1), o: n(i, "opacity", .5), c: n(i, "color", "0,0,0"), n: n(i, "count", 99)
    31             }
    32         }
    33 
    34         function o() {
    35             a = m.width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
    36                 34
    37             c = m.height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
    38         }
    39 
    40         function i() {
    41             r.clearRect(0, 0, a, c);
    42 
    43             var n, e, t, o, m, l;
    44             s.forEach(function (i, x) {
    45 
    46                 for (i.x += i.xa, i.y += i.ya, i.xa *= i.x > a || i.x < 0 ? -1 : 1, i.ya *= i.y > c || i.y < 0 ? -1 : 1, r.fillRect(i.x - .5, i.y - .5, 1, 1), e = x + 1; e < u.length; e++) n = u[e],
    47 
    48                 null !== n.x && null !== n.y && (o = i.x - n.x, m = i.y - n.y,
    49                     l = o * o + m * m, l < n.max && (n === y && l >= n.max / 2 && (i.x -= .03 * o, i.y -= .03 * m),
    50                     t = (n.max - l) / n.max, r.beginPath(), r.lineWidth = t / 2, r.strokeStyle = "rgba(" + d.c + "," + (t + .2) + ")", r.moveTo(i.x, i.y), r.lineTo(n.x, n.y), r.stroke()))
    51             }),
    52                 x(i)
    53         }
    54 
    55         var a, c, u, m = document.createElement("canvas"),
    56             d = t(), l = "c_n" + d.l, r = m.getContext("2d"),
    57             x = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
    58                 function (n) {
    59                     window.setTimeout(n, 1e3 / 45)
    60                 },
    61             w = Math.random, y = {x: null, y: null, max: 2e4};
    62         m.id = l, m.style.cssText = "position:fixed;top:0;left:0;z-index:" + d.z + ";opacity:" + d.o, e("body")[0].appendChild(m), o(), window.onresize = o,
    63             window.onmousemove = function (n) {
    64                 n = n || window.event, y.x = n.clientX, y.y = n.clientY
    65             },
    66             window.onmouseout = function () {
    67                 y.x = null, y.y = null
    68             };
    69         for (var s = [], f = 0; d.n > f; f++) {
    70             var h = w() * a, g = w() * c, v = 2 * w() - 1, p = 2 * w() - 1;
    71             s.push({x: h, y: g, xa: v, ya: p, max: 6e3})
    72         }
    73         u = s.concat([y]),
    74             setTimeout(function () {
    75                 i()
    76             }, 100)
    77     }();
    78 </script>
    79 </body>
    80 </html>

     

  • 相关阅读:
    响应式布局和BootStrap 全局CSS样式
    javascript中的undefined与null的区别
    before(),after(),prepend(),append()等新DOM方法简介
    解决文字和text-decoration:underline下划线重叠问题
    CSS3 linear-gradient线性渐变实现虚线等简单实用图形
    用Javascript获取页面元素的位置
    rem、px、em(手机端h5页面屏幕适配的几种方法)
    用flex和rem实现移动端页面
    HTML5新增的form属性简介(转载至张鑫旭)
    vue实现图片放大
  • 原文地址:https://www.cnblogs.com/xiaoh1/p/12061343.html
Copyright © 2011-2022 走看看