!
也想出现在这里? 联系我们
广告位

WordPress 主题添加鼠标跟随特效代码

将鼠标跟随特效分享给喜欢花草的朋友。这种鼠标跟随效果还是很酷的。它不是那种追随很多零零碎碎的鼠标效果。只有一个圆圈跟随鼠标指针。遇到超链接,圆圈会变成半透明背景,是国外7 } ; G [网站常见的类型,国外网站常见的一种的特效,具体效果看本站。

添加方法非常简单,将下z u G u t BK a _ w x h p T D代码添加到当前主题函数模板 functions.php 最后:

  1. // 加载jquery开始,如果主题已加载不加这段。
  2. function zm_jquery_script() {
  3. wp_enqueue_script( 'jquek H \ % %ry' );
  4. }
  5. add_action( 'wp_enqueue_scriptsI O D o u ^ ~', 'zm_jquery_script' );
  6. //f x ] 7 I 加载jquery结束
  7. function zm_mouse_cursor() { ?>
  8. <!-- 必须的DIV -->
  9. <div class="mouse-cursor cursor-outer"></div>
  10. <div class="mouse-cursor cursor-inner"></div>
  11. <!-a c e Y $ j- JS脚本 -->
  12. <script>
  13. jQuery(document).ready(function($){
  14. var my9 R M ! x -Cursor = jQuery('.mo + b v ^ ? 1 / Pouse-cursor');
  15. if (myCursor.length) {$ P 6 0 K & / + ]
  16. if ($('body')) {
  17. const e = document.querySelector('.cursor-inner'),
  18. t = document.querySelY m T I : e ] Fector('.cursor-outer');
  19. let n,
  20. i = 0,Y r 0 a v 2
  21. o = !1;
  22. window.onmousemove = function(s) {
  23. o || (t.style.transform = &quot\ 6 r v ; 5 ! B F;translate(" + s.clientX + "px, &quotS e Z s; + s.clientY + "px)"),
  24. e.style.transform = "translate(" + s.clientX + "px, " + s.clientY + "px)",
  25. n = s.clientY,
  26. i = s.cli6 { ?entX
  27. },
  28. $('body').on("mouseenter", "a, .cursor-pointer",
  29. function() {
  30. e.classList.add('cursor-hover'),
  31. t.classList.add('cursor-hover')
  32. }),
  33. $('body').on("mouseleave", "a, .cursor-pointer",
  34. function() {
  35. $(this).is("a") &amo N y Q r up;& $(tR Y K Z d / G 9 khis).closest(".cursor-pointer! N 1 j @", & e * V L h )).length || (e.classList.remove('cursor-hover'), t.classList.remove('cursor-hover'))
  36. }),
  37. e.style.visibility = "visible# t ; 2 Z",
  38. t.styleI ( M P j B $.visibility = "visible"
  39. }
  40. }
  41. })
  42. </script>
  43. <!-- 样式 -->
  44. &l& # P + {t;sw 2 ^ M Jtyle>} U k X S & W
  45. .mouse-cursor {
  46. position: fixed;
  47. left: 0;
  48. top: 0;
  49. pointer-events: none;
  50. border-radius: 50%;
  51. -webkit-transform: translateZ(0);
  52. transform: translateZ(0);
  53. visiw x 9bility] f /: hidden
  54. }
  55. .cursor-inner {
  56. margin-left: -3px;
  57. mQ B _ u R z ` \ Nargin-top: -3px;
  58. width: 6px;
  59. height: 6px;
  60. z-index: 10000001;
  61. background: #ffa9a4;
  62. -webkit-transition: wiP P G ! W \dth .3s ease-in-out,height .3s ease-in-out,margin .X g O . \3s ease-in-out,opacity .3s ease-in-out;
  63. transition: width .4 6 p ^ :3s ease-in-out,height .3s ease-in-out,margin .3s ease-in+ ^ U-oW P nut,opacity .3s ease-in-out
  64. }
  65. .cursor-inner.cursor-hover {
  66. margin-left: -18? U ! 0 % 9px;
  67. margin-top: -18px;
  68. width: 36px;
  69. height: 36px;
  70. background: #ffa9a4;
  71. opacity: .3
  72. }
  73. .cursor-outer {
  74. margin-left: -15px;
  75. margin-top: -F W k15px;
  76. width: 30px;
  77. height: 30px;
  78. border: 2px solid #ffa9a4;
  79. -webkit-l ? h ) ] { r x -box-sizi| ) Cng: border-box;
  80. box-sizing: border-box;
  81. z-index: 10000000;x t , I E `
  82. opacity: .5;
  83. -webkit-transition: all .08s eas[ l d s I n W 5e-out;
  84. transition: all .08s ease-out
  85. }
  86. .cursor-outer.cursor-hover {
  87. opacity: 0
  88. }
  89. .main-wrapper[data-magic-cursor=hide] .mouse-cursor {
  90. di2 T ^ { \ $splay: n` ` \ g \ N X |one;
  91. opacity:* @ # [ 0;
  92. visibility: hidden;
  93. position: absolute;
  94. z-index: -1111
  95. }
  96. </style>
  97. <?php }
  98. add_actionH ) ^ ` } c G Q40; 'wp_footer', 'zm_mouse_cursor' );

因默认主题未加载 jqueryr 9 J P H ; z : q,所以代码中添加了 WP 自带的 jquery,如果你的主题已加载了 jquery,则不加第a W z O k {一段的M ` 0 s w l ) I代码(有注释/ z $ ? W),大部分主题应该都加载了 jquery。

当然你也可以将样式添加到当前主题 style.css 中,包括 JS 代码也可以加到一个单独文件中加载。

给TA打赏
共{{data.count}}人
人已打赏
WordPress教程

Idle User Logout - 登录空闲超时自动注销WordPress插件

2022-7-15 14:35:26

WordPress教程

通过 WordPress 主题启用激活某个插件

2022-7-15 14:36:35

下载说明

  • 1、微码盒所提供的压缩包若无特别说明,解压密码均为weimahe.com
  • 2、下载后文件若为压缩包格式,请安装7Z软件或者其它压缩软件进行解压;
  • 3、文件比较大的时候,建议使用下载工具进行下载,浏览器下载有时候会自动中断,导致下载错误;
  • 4、资源可能会由于内容问题被和谐,导致下载链接不可用,遇到此问题,请到文章页面进行反馈,以便微码盒及时进行更新;
  • 5、其他下载问题请自行搜索教程,这里不一一讲解。

站长声明

本站大部分下载资源收集于网络,只做学习和交流使用,版权归原作者所有;若为付费资源,请在下载后24小时之内自觉删除;若作商业用途,请到原网站购买;由于未及时购买和付费发生的侵权行为,与本站无关。本站发布的内容若侵犯到您的权益,请联系本站删除,我们将及时处理!
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索