网络 · 2020年11月23日 22

给wordpress加点特效(鼠标点击)

WordPress 添加鼠标点击特效
实际上这种教程在网上搜索一下有一大堆,已经是各大博主玩烂的东西了。不过既然给自己的博客加上了这个,那就也凑数发一篇吧。

找到自己wp的主题文件夹,在 footer.php文件中的

<?php wp_footer(); ?>

代码前,添加下面代码

<script type="text/javascript">
var a_idx = 0;
jQuery(document).ready(function($) {
$("body").click(function(e) {
var a = new Array("文字", "文字2");
var $i = $("<span/>").text(a[a_idx]);
a_idx = (a_idx + 1) % a.length;
var x = e.pageX,
y = e.pageY;
$i.css({
"z-index": 9999,
"top": y - 20,
"left": x,
"position": "absolute",
"font-weight": "bold",
"color": "#ff6651"
});
$("body").append($i);
$i.animate({
"top": y - 180,
"opacity": 0
},
1500,
function() {
$i.remove();
});
});
});
</script>

然后刷新一下网页,就有了

%d