点击页面动态显示字段

1看代码有注释

自己引jquery,以下代码是在script标签里面

//这是你点击页面出现的字
var arr=[“a”,“b”,“c”,“d”];
//鼠标点击特效
//页面加载事件
jQuery(function () {

//声明变量
var hits = 0;

//给页面创建点击事件
$(“html”).click(function (e) {

//创建颜色库
//随机颜色
//创建颜色码
//前颜色码库
const frontCorlor = new Array(‘00’, ‘11’, ‘22’, ‘33’, ‘44’, ‘55’, ‘66’, ‘77’, ‘88’, ‘99’,
‘aa’, ‘bb’, ‘cc’, ‘dd’, ‘ee’, ‘ff’);
//中颜色码库
const centreCorlor = new Array(‘00’, ‘11’, ‘22’, ‘33’, ‘44’, ‘55’, ‘66’, ‘77’, ‘88’, ‘99’,
‘aa’, ‘bb’, ‘cc’, ‘dd’, ‘ee’, ‘ff’);
//后颜色码库
const queenCorlor = new Array(‘00’, ‘11’, ‘22’, ‘33’, ‘44’, ‘55’, ‘66’, ‘77’, ‘88’, ‘99’,
‘aa’, ‘bb’, ‘cc’, ‘dd’, ‘ee’, ‘ff’);

//从颜色库选取一种颜色;当然这是数组的方式;随机性
//前颜色码
var frontcode = Math.floor(Math.random() * frontCorlor.length);
//中颜色码
var centrecode = Math.floor(Math.random() * centreCorlor.length);
//后颜色码
var queencode = Math.floor(Math.random() * queenCorlor.length);

// console.log("frontcode = " + frontcode + “; centrecode = " + centrecode + “; queencode = " + queencode + “;”)
// console.log(”#” + frontCorlor[frontcode] + centreCorlor[centrecode] + queenCorlor[queencode]);

//每当鼠标点击页面增加点击数
//循环数,想循环的调一下这个数字可以当点击你写的字一遍了,继续点会再从第一个字开始

    hits++;
    if (hits==5){
        hits=1;
    }

//创建元素; 创建的元素是span元素,这个元素的内容是"鼠标点击了第" + hits(这个是一个变量) + “次”
var extablish = $("").text(arr[hits-1]);

//在页面上添加span元素
jQuery(“html”).append(extablish);

//获取鼠标点击坐标
//横坐标
var abscisse = e.pageX;
//纵坐标
var ordinate = e.pageY;

//给span元素添加css样式
extablish.css({
“z-index”: 999, //设置或获取定位对象的堆叠次序(z-index):999
“top”: ordinate - 20, //上(top):y-20
“left”: abscisse, //左:x
“position”: “absolute”, //定位:绝对定位
“font-weight”: “bold”, //字体粗细:粗体
“color”: “#” + frontCorlor[frontcode] + centreCorlor[centrecode] + queenCorlor[queencode], //颜色:绿色
“user-select”: “none”, //使文字不被选中
“font-size”: “100px”,
});

    extablish.animate({
            "top": ordinate - 180, //上:y-180
            "opacity": 0 //透明度(opacity):0
        }, 2000, //1500,调节动画速度
        function () { //功能函数
            extablish.remove(); //$i的删除
        }
    );
})

})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值