[英]jQuery fade in active element, fade out inactive elements
Using: 使用:
$(event.currentTarget).fadeTo(0, 1);
Seems to work, while using: 在使用时似乎可以工作:
$('.btn .active').fadeTo(0, 1);
Does not. 才不是。 Any idea why?
知道为什么吗?
jsFiddle link here: http://jsfiddle.net/SeanKilleen/fwerK/ 此处的jsFiddle链接: http : //jsfiddle.net/SeanKilleen/fwerK/
JavasScript code below: 下面的JavasScript代码:
var global_loggedOnUser = "User1";
$(document).ready(function () {
var viewmodel = (function () {
this.feedbacktype = ko.observable("None");
this.currentPage = ko.observable(location.href);
this.currentUsername = global_loggedOnUser;
this.updateFeedbackType = function (item, event) {
var newText = $(event.currentTarget).children("span").text();
$('#buttonList button').removeClass('active');
$(event.currentTarget).addClass('active');
feedbacktype(newText);
$('.btn').not('.active').fadeTo('fast', 0.3);
$('.btn .active').fadeTo('fast', 1);
};
return {
pageUserIsOn: currentPage,
theUser: currentUsername,
feedbackType: feedbacktype
};
})();
ko.applyBindings(viewmodel);
});
I'm trying to accomplish this by adding an "active" class to the button and removing it from all others, and then performing the fade based on class. 我正在尝试通过向按钮添加“活动”类并将其从所有其他按钮中删除,然后基于该类执行淡入淡出来实现此目的。
What am I missing? 我想念什么?
Remove the space between the classes, you want to select elements with both classes not .active
descendants of .btn
删除类之间的空间,您要选择两个类都不是
.active
后代的.btn
$('.btn .active').fadeTo('fast', 1);
should be 应该
$('.btn.active').fadeTo('fast', 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.