jQuery一段代码不懂,麻烦帮忙加个注释
random=function(t,e){returnt&&"number"==typeoft.length?t[Math.floor(Math.random()*t.l...
random = function(t, e) {
return t && "number" == typeof t.length ? t[Math.floor(Math.random() * t.length)] : ("number" != typeof e && (e = t || 1, t = 0), t + Math.random() * (e - t))
};
TinyHeart.STYLES = ["t01dc2e861029c8a8ca", "t016cc24a48997d651a", "t01dd2a63c80cbdbc30"],
TinyHeart.prototype = {
init: function(t, e) {
this.alive = !0,
this.scale = random(.3, .7),
this.opacity = random(50, 70) / 100,
this.style = random(TinyHeart.STYLES);
var s = random(2 * Math.PI);
this.x = t + 80 * Math.sin(s) - 48 * this.scale / 2,
this.y = e + 80 * Math.cos(s) - 42 * this.scale / 2,
this.theta = random(2 * Math.PI),
this.drag = random(.9, .99),
this.wander = random(.5, 2),
this.force = random(.1, .4),
this.vx = Math.sin(this.theta) * this.force,
this.vy = Math.cos(this.theta) * this.force,
this.draw()
},
move: function() {
this.x += this.vx,
this.y += this.vy,
this.vx *= this.drag,
this.vy *= this.drag,
this.theta += random( - .5, .5) * this.wander,
this.vx += .1 * Math.sin(this.theta),
this.vy += .1 * Math.cos(this.theta),
this.scale *= .995,
this.opacity *= .96,
this.alive = this.opacity > .1,
this.draw()
}, 展开
return t && "number" == typeof t.length ? t[Math.floor(Math.random() * t.length)] : ("number" != typeof e && (e = t || 1, t = 0), t + Math.random() * (e - t))
};
TinyHeart.STYLES = ["t01dc2e861029c8a8ca", "t016cc24a48997d651a", "t01dd2a63c80cbdbc30"],
TinyHeart.prototype = {
init: function(t, e) {
this.alive = !0,
this.scale = random(.3, .7),
this.opacity = random(50, 70) / 100,
this.style = random(TinyHeart.STYLES);
var s = random(2 * Math.PI);
this.x = t + 80 * Math.sin(s) - 48 * this.scale / 2,
this.y = e + 80 * Math.cos(s) - 42 * this.scale / 2,
this.theta = random(2 * Math.PI),
this.drag = random(.9, .99),
this.wander = random(.5, 2),
this.force = random(.1, .4),
this.vx = Math.sin(this.theta) * this.force,
this.vy = Math.cos(this.theta) * this.force,
this.draw()
},
move: function() {
this.x += this.vx,
this.y += this.vy,
this.vx *= this.drag,
this.vy *= this.drag,
this.theta += random( - .5, .5) * this.wander,
this.vx += .1 * Math.sin(this.theta),
this.vy += .1 * Math.cos(this.theta),
this.scale *= .995,
this.opacity *= .96,
this.alive = this.opacity > .1,
this.draw()
}, 展开
2个回答
2017-06-12 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
var durl = $("#cplb ul").attr("data-url");获取div下面的ul元素中的data-url并赋值给drul;
$("#cplb ul li").each(function(){
var url = $(this).find("a").attr("href");
if(url==durl){
$("#cplb ul li").removeClass("current");
$(this).addClass("current");
}
});
然后是遍历出当前有多少个li元素;
创建 变量(url)= 当前li元素找到下面的a标签并改变它的href值;
判断:
如果当前a元素的href值=ul的地址;
那么鼠标移动上去吧所有的Li元素中包含current类名的名字删掉;
并给当前的li元素添加current类名;
这个方法也就是经常用在导航模块中,current的属性可以在css中设置,可以移动上去为背景图片,颜色都可以,添加其他css3效果也行
$("#cplb ul li").each(function(){
var url = $(this).find("a").attr("href");
if(url==durl){
$("#cplb ul li").removeClass("current");
$(this).addClass("current");
}
});
然后是遍历出当前有多少个li元素;
创建 变量(url)= 当前li元素找到下面的a标签并改变它的href值;
判断:
如果当前a元素的href值=ul的地址;
那么鼠标移动上去吧所有的Li元素中包含current类名的名字删掉;
并给当前的li元素添加current类名;
这个方法也就是经常用在导航模块中,current的属性可以在css中设置,可以移动上去为背景图片,颜色都可以,添加其他css3效果也行
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询