css3

鼠标点击弹出字

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Document</title>
  </head>

  <body>
    <script>
      ;(function () {
        let arrIndex = 0
        window.onclick = function (event) {
          let textArry = new Array(
            '❤富强❤',
            '❤民主❤',
            '❤文明❤',
            '❤和谐❤',
            '❤自由❤',
            '❤平等❤',
            '❤公正❤',
            '❤法治❤',
            '❤爱国❤',
            '❤敬业❤',
            '❤诚信❤',
            '❤友善❤'
          )

          let heart = document.createElement('b') //创建b元素
          heart.onselectstart = new Function('event.returnValue=false') //防止拖动
          document.body.appendChild(heart).innerHTML = textArry[arrIndex] //将b元素添加到页面上
          arrIndex = (arrIndex + 1) % textArry.length
          heart.style.cssText = 'position: fixed;left:-100%;' //给p元素设置样式
          let _fontSize = 16, // 字体大小
            clientX = event.clientX - _fontSize / 2, // 横坐标
            clientY = event.clientY - _fontSize, // 纵坐标
            randomC = randomColor(), // 随机颜色
            opacity = 1, // 透明度
            s = 1.2 // 放大缩小

          let timer = setInterval(function () {
            //添加定时器
            if (opacity <= 0) {
              document.body.removeChild(heart)
              clearInterval(timer)
            } else {
              heart.style.cssText =
                'font-size:16px;cursor: default;position: fixed;color:' +
                randomC +
                ';left:' +
                clientX +
                'px;top:' +
                clientY +
                'px;opacity:' +
                opacity +
                ';transform:scale(' +
                s +
                ');'

              clientY--
              opacity -= 0.016
              s += 0.002
            }
          }, 15)
        }

        // 随机颜色
        function randomColor() {
          return (
            'rgb(' +
            ~~(Math.random() * 255) +
            ',' +
            ~~(Math.random() * 255) +
            ',' +
            ~~(Math.random() * 255) +
            ')'
          )
        }
      })()

      /**
       * ~~去掉小数
       */
      /* let ccc = 3.9999
      let ddd = ~~ccc
      console.log(ddd,'====') */
    </script>
  </body>
</html>

# 鼠标点击弹出爱心

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <!-- 网页鼠标点击特效(爱心) -->
    <script type="text/javascript">
      !(function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++)
            s[e].alpha <= 0
              ? (t.body.removeChild(s[e].el), s.splice(e, 1))
              : (s[e].y--,
                (s[e].scale += 0.004),
                (s[e].alpha -= 0.013),
                (s[e].el.style.cssText =
                  'left:' +
                  s[e].x +
                  'px;top:' +
                  s[e].y +
                  'px;opacity:' +
                  s[e].alpha +
                  ';transform:scale(' +
                  s[e].scale +
                  ',' +
                  s[e].scale +
                  ') rotate(45deg);background:' +
                  s[e].color +
                  ';z-index:99999'))
          requestAnimationFrame(r)
        }

        function n() {
          var t = 'function' == typeof e.onclick && e.onclick
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement('div')
          ;(a.className = 'heart'),
            s.push({
              el: a,
              x: e.clientX - 5,
              y: e.clientY - 5,
              scale: 1,
              alpha: 1,
              color: c(),
            }),
            t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement('style')
          a.type = 'text/css'
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName('head')[0].appendChild(a)
        }

        function c() {
          return (
            'rgb(' +
            ~~(255 * Math.random()) +
            ',' +
            ~~(255 * Math.random()) +
            ',' +
            ~~(255 * Math.random()) +
            ')'
          )
        }
        var s = []
        ;(e.requestAnimationFrame =
          e.requestAnimationFrame ||
          e.webkitRequestAnimationFrame ||
          e.mozRequestAnimationFrame ||
          e.oRequestAnimationFrame ||
          e.msRequestAnimationFrame ||
          function (e) {
            setTimeout(e, 1e3 / 60)
          }),
          i(
            ".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"
          ),
          n(),
          r()
      })(window, document)
    </script>
  </body>
</html>

上次更新: