找回密码
 立即注册
搜索
查看: 4102|回复: 0

鼠标点击弹出随机文字,富强,民主等

[复制链接]
  • 打卡等级:暂无等级
  • 打卡总天数:203
  • 打卡月天数:27
  • 打卡总奖励:159
  • 最近打卡:2025-11-27 04:14:21
灌水成绩
14285
49
2035369
主题
帖子
积分

等级头衔

ID : 1

管理员

积分成就 威望 : 999999
贡献 : 9999
下载币 : 11038
在线时间 : 1062 小时
注册时间 : 2013-9-5
最后登录 : 2025-11-27

发表于 昨天 11:17 | 显示全部楼层 |阅读模式 IP:广东
免责
免费领取大流量卡,每日更新蔡州手游APP源码密码加入群聊接手游搭建—``下载币--购买服务器☆长期招聘游戏测试员(无偿),有兴趣联系站长QQ58493525微信A0396C
  1. <script type="text/javascript">
  2.     window.onload = function() {
  3.         //定义点击出现文字类
  4.         function ClickFrontShow() {
  5.             //定义所需文字和颜色
  6.             this.fron = ['高兴', '开心', '❤','富强', '民主', '喜悦', '欢欣', '欢畅', '欢腾', '雀跃', '欢快'];
  7.             this.colo = ['#FF69B4', '#ff6651', 'orange', '#FF00FF', '#00FF7F', '#00BFFF', '#BA55D3'];
  8.             //获取body元素
  9.             this.elBody = document.getElementsByTagName("body")[0];
  10.             //初始化randomNum
  11.             this.randomNum = null;
  12.             //初始化字体inde
  13.             this.finde = 0;
  14.             //初始化className
  15.             this.cls = 0;
  16.         }
  17.         //定义初始化
  18.         ClickFrontShow.prototype.init = function(frontArray, colorArray) {
  19.             //自定义颜色和字体
  20.             this.fron = frontArray || this.fron;
  21.             this.colo = colorArray || this.colo;

  22.             this.listenMouse();
  23.         }

  24.         //创建文字
  25.         ClickFrontShow.prototype.createFront = function (classname) {
  26.             var self = this;
  27.             let ospan = document.createElement('span');
  28.             //设置样式
  29.             let cssText = "position:absolute; width: 80px; height: 20px; cursor: default; transform: translate(-50%,-50%); font-weight: bold; opacity: 1; z-index: 1000; transition: 1s;";
  30.             //随机字体和颜色
  31.             let randomFront = self.fron[self.finde];
  32.             let randomColor = self.colo[Math.round(Math.random()*(self.colo.length-1))];
  33.             //字体下标增1
  34.             self.finde = (self.finde+1) % self.fron.length;
  35.             //向body中添加元素
  36.             self.elBody.appendChild(ospan);
  37.             //绑定一个classname
  38.             ospan.className = String(classname);
  39.             //添加样式
  40.             ospan.style.cssText = cssText + "-moz-user-select: none;-webkit-user-select: none;-ms-user-select: none;user-select: none;"
  41.             ospan.style.color = randomColor;
  42.             ospan.innerHTML = randomFront;
  43.         }

  44.         //监听鼠标点击
  45.         ClickFrontShow.prototype.listenMouse = function() {
  46.             var self = this;
  47.             //鼠标点击事件
  48.             document.onclick = function(e) {
  49.                 //避免classname值重复导致出现bug
  50.                 if(self.cls === 20){
  51.                     self.cls = 0;
  52.                 }else{
  53.                     self.cls += 1;
  54.                 }
  55.                 //创建文字
  56.                 self.createFront(self.cls);
  57.                 let el = document.getElementsByClassName(self.cls)[0];

  58.                 //鼠标点击位置
  59.                 el.style.left = e.clientX + 'px';
  60.                 el.style.top = e.clientY + 'px';

  61.                 //过时改变
  62.                 setTimeout(function() {
  63.                     el.style.opacity = 0;
  64.                     el.style.top = el.offsetTop - 100 + 'px';
  65.                 }, 100);
  66.                 //过时清除
  67.                 setTimeout(function() {
  68.                     self.elBody.removeChild(el);
  69.                 }, 3000);
  70.             }

  71.         }
  72.         //实例化
  73.         var frontShow = new ClickFrontShow();
  74.         //用户可在此传递参数,默认第一个参数是字体数组;
  75.         //第二个参数是颜色数组,必须是数组类型!
  76.         frontShow.init();
  77.     }
  78. </script>
  79. </body>
复制代码


免责
帖子地址打造全网最多免费游戏网站
今日来客 列表模式
回复

使用道具 举报

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

本版积分规则

本站已运行 ©2013-2026

QQ|Archiver|手机版|小黑屋|蔡州手游 |网站地图

GMT+8, 2025-11-27 15:05

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表