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

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

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

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

代码如下:

  1. <script type="text/javascript">
  2. /* 虚拟世界博客 www.xnworld.com */
  3. var a_idx = 0;
  4. jQuery(document).ready(function($) {
  5. $("body").click(function(e) {
  6. var a = new Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正" ,"法治", "爱国", "敬业", "诚信", "友善");
  7. var $i = $("<span/>").text(a[a_idx]);
  8. a_idx = (a_idx + 1) % a.length;
  9. var x = e.pageX,
  10. y = e.pageY;
  11. $i.css({
  12. "z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
  13. "top": y - 20,
  14. "left": x,
  15. "position": "absolute",
  16. "font-weight": "bold",
  17. "color": "#ff6651"
  18. });
  19. $("body").append($i);
  20. $i.animate({
  21. "top": y - 180,
  22. "opacity": 0
  23. },
  24. 1500,
  25. function() {
  26. $i.remove();
  27. });
  28. });
  29. });
  30. </script>

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

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

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

代码如下:

  1. <script>
  2. (function(window,document,undefined){
  3. var hearts = [];
  4. window.requestAnimationFrame = (function(){
  5. return window.requestAnimationFrame ||
  6. window.webkitRequestAnimationFrame ||
  7. window.mozRequestAnimationFrame ||
  8. window.oRequestAnimationFrame ||
  9. window.msRequestAnimationFrame ||
  10. function (callback){
  11. setTimeout(callback,1000/60);
  12. }
  13. })();
  14. init();
  15. function init(){
  16. 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;}");
  17. attachEvent();
  18. gameloop();
  19. }
  20. function gameloop(){
  21. for(var i=0;i<hearts.length;i++){
  22. if(hearts[i].alpha <=0){
  23. document.body.removeChild(hearts[i].el);
  24. hearts.splice(i,1);
  25. continue;
  26. }
  27. hearts[i].y--;
  28. hearts[i].scale += 0.004;
  29. hearts[i].alpha -= 0.013;
  30. 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;
  31. }
  32. requestAnimationFrame(gameloop);
  33. }
  34. function attachEvent(){
  35. var old = typeof window.onclick==="function" && window.onclick;
  36. window.onclick = function(event){
  37. old && old();
  38. createHeart(event);
  39. }
  40. }
  41. function createHeart(event){
  42. var d = document.createElement("div");
  43. d.className = "heart";
  44. hearts.push({
  45. el : d,
  46. x : event.clientX - 5,
  47. y : event.clientY - 5,
  48. scale : 1,
  49. alpha : 1,
  50. color : randomColor()
  51. });
  52. document.body.appendChild(d);
  53. }
  54. function css(css){
  55. var style = document.createElement("style");
  56. style.type="text/css";
  57. try{
  58. style.appendChild(document.createTextNode(css));
  59. }catch(ex){
  60. style.styleSheet.cssText = css;
  61. }
  62. document.getElementsByTagName('head')[0].appendChild(style);
  63. }
  64. function randomColor(){
  65. return "rgb("+(~~(Math.random()*255))+","+(~~(Math.random()*255))+","+(~~(Math.random()*255))+")";
  66. }
  67. })(window,document);
  68. </script>

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

有问必答~

猜你喜欢  

网赚项目收录网——让你的口袋鼓起来! http://shoulu.xnworld.com/

段子网——笑到你怀疑人生! http://duanzi.xnworld.com/

养生网——为健康保驾护航! http://yangsheng.xnworld.com/

如果您想获得最新赚钱项目,请加下方站长微信,进微信群【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:

确定