返回列表 发布新帖
查看: 531|回复: 0

JS代码实现鼠标点击爱心特效

捣蛋鬼魔神·索伦森

梦之瑶-飞哥发表于 2019-10-27 12:51:49 | 查看全部 |阅读模式

您需要登录账号才能看到图片及隐藏内容,马上注册享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
使用非常简单,需要在哪个页面显示就把代码放到哪个页面就行了。
  1. <script>
  2.         !function(e, t, a) {
  3.                 function r() {
  4.                         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 += .004, s[e].alpha -= .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");
  5.                         requestAnimationFrame(r)
  6.                 }
  7.                 function n() {
  8.                         var t = "function" == typeof e.onclick && e.onclick;
  9.                         e.onclick = function(e) {
  10.                                 t && t(),
  11.                                         o(e)
  12.                         }
  13.                 }
  14.                 function o(e) {
  15.                         var a = t.createElement("div");
  16.                         a.className = "heart",
  17.                                 s.push({
  18.                                         el: a,
  19.                                         x: e.clientX - 5,
  20.                                         y: e.clientY - 5,
  21.                                         scale: 1,
  22.                                         alpha: 1,
  23.                                         color: c()
  24.                                 }),
  25.                                 t.body.appendChild(a)
  26.                 }
  27.                 function i(e) {
  28.                         var a = t.createElement("style");
  29.                         a.type = "text/css";
  30.                         try {
  31.                                 a.appendChild(t.createTextNode(e))
  32.                         } catch(t) {
  33.                                 a.styleSheet.cssText = e
  34.                         }
  35.                         t.getElementsByTagName("head")[0].appendChild(a)
  36.                 }
  37.                 function c() {
  38.                         return "rgb(" + ~~ (255 * Math.random()) + "," + ~~ (255 * Math.random()) + "," + ~~ (255 * Math.random()) + ")"
  39.                 }
  40.                 var s = [];
  41.                 e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame ||
  42.                         function(e) {
  43.                                 setTimeout(e, 1e3 / 60)
  44.                         },
  45.                         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;}"),
  46.                         n(),
  47.                         r()
  48.         } (window, document);
  49. </script>


复制代码



<
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

投诉/建议联系

xm520vip@gmail.com

未经授权禁止转载,复制和建立镜像,
如有违反,追究法律责任
  • 关注公众号
  • 关注小程序
Copyright © 2001-2025 灵歆论坛 版权所有 All Rights Reserved. |网站地图
关灯 在本版发帖
扫一扫进入小程序页面
QQ客服返回顶部
快速回复 返回顶部 返回列表