WordPress鼠标左键点击显示富强/民主/爱国等文字的方法

2020年2月27日一建二建评论331阅读模式
WordPress鼠标左键点击显示富强/民主/爱国等文字的方法

WordPress鼠标点击特效源码下载,该源码是PHP源码。可以实现wordpress博客的背景显示”富强”, “民主”, “文明”, “和谐”, “自由”, “平等”, “公正” ,”法治”, “爱国”, “敬业”, “诚信”等文字效果。加上了该段代码,可以让你的网站,在用户任意位置点击鼠标,显示上面文字的特效。

WordPress鼠标左键点击显示富强/民主/爱国等文字的方法

代码如下:

<script type="text/javascript">
/*  虚拟世界博客  www.xnworld.com  */
var a_idx = 0;
jQuery(document).ready(function($) {
$("body").click(function(e) {
var a = new Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正" ,"法治", "爱国", "敬业", "诚信", "友善");
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": 999999999999999999999999999999999999999999999999999999999999999999999,
"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>

将上面的代码添加到主题页脚(footer.php)文件的 php wp_footer(); ? 之前即可,然后保存代码上传到服务器,即可实现。

给网站添加鼠标点击爱心弹出效果:
wordpress网站鼠标点击爱心特效教程源码下载。有些网站在鼠标点击的时候有添加+1这种红色数字慢慢变大变淡的淡出和上升效果,觉得蛮有趣的,但是不管是随机数字还是累积数字,用久了闲鱼觉得还是蛮单调的。
而这里要介绍的就是一个将数字变成一个爱心物件淡出的效果,作为页面的装饰,点击鼠标的时候就会弹出这种意外的小惊喜,然后消失,会让网页不会显得那么单调。

WordPress鼠标左键点击显示富强/民主/爱国等文字的方法

代码如下:

<script>
(function(window,document,undefined){  
var hearts = [];  
window.requestAnimationFrame = (function(){  
return window.requestAnimationFrame ||  
window.webkitRequestAnimationFrame ||  
window.mozRequestAnimationFrame ||  
window.oRequestAnimationFrame ||  
window.msRequestAnimationFrame ||  
function (callback){  
setTimeout(callback,1000/60);  
}  
})();  
init();  
function init(){  
css(".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: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");  
attachEvent();  
gameloop();  
}  
function gameloop(){  
for(var i=0;i<hearts.length;i++){  
if(hearts[i].alpha <=0){  
document.body.removeChild(hearts[i].el);  
hearts.splice(i,1);  
continue;  
}  
hearts[i].y--;  
hearts[i].scale += 0.004;  
hearts[i].alpha -= 0.013;  
hearts[i].el.style.cssText = "left:"+hearts[i].x+"px;top:"+hearts[i].y+"px;opacity:"+hearts[i].alpha+";transform:scale("+hearts[i].scale+","+hearts[i].scale+") rotate(45deg);background:"+hearts[i].color;  
}  
requestAnimationFrame(gameloop);  
}  
function attachEvent(){  
var old = typeof window.onclick==="function" && window.onclick;  
window.onclick = function(event){  
old && old();  
createHeart(event);  
}  
}  
function createHeart(event){  
var d = document.createElement("div");  
d.className = "heart";  
hearts.push({  
el : d,  
x : event.clientX - 5,  
y : event.clientY - 5,  
scale : 1,  
alpha : 1,  
color : randomColor()  
});  
document.body.appendChild(d);  
}  
function css(css){  
var style = document.createElement("style");  
style.type="text/css";  
try{  
style.appendChild(document.createTextNode(css));  
}catch(ex){  
style.styleSheet.cssText = css;  
}  
document.getElementsByTagName('head')[0].appendChild(style);  
}  
function randomColor(){  
return "rgb("+(~~(Math.random()*255))+","+(~~(Math.random()*255))+","+(~~(Math.random()*255))+")";  
}  
})(window,document);
</script>

以上代码,亲测,完全OK,大家有啥问题,可以留言~

有问必答~

猜你喜欢  

更多精彩自媒体,请访问【我爱自媒体】 www.woaizimeiti.com

支付宝每天领0.1~100元红包哦【每天可领】 https://www.xnworld.com/12371.html

如果您想看最新精彩电影 & 购物更省钱,请加下方站长微信,进微信群【24小时更新】:
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 最新电影
  • 微信扫一扫
  • weinxin
虚拟世界
  • 本文由 发表于 2020年2月27日
  • 转载请务必保留本文链接:https://www.xnworld.com/82.html
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定