开发者

jquery running same function on multiple elements relatives to 'This'

开发者 https://www.devze.com 2023-04-04 02:44 出处:网络
$(\".column a\").mouseenter(function() { var color_column=$(this).closest(\'.column\').children(\'.coloured-strip\').css(\'color\');
$(".column a").mouseenter(function() {
var color_column=$(this).closest('.column').children('.coloured-strip').css('color');

$(this).siblings('p').animate({color:color_column},2000);
$(this).an开发者_高级运维imate({color:color_column},2000);
});

There's any way I can group the two animate functions into one since they're identical?

thanks luca


Sure, just use .add():

$(this).siblings('p').add(this).animate({color:color_column},2000);


You can use the andSelf() method:

$(this).siblings('p').andSelf().animate({color:color_column},2000);


Instead of:

$(this).siblings('p').animate({color:color_column},2000);
$(this).animate({color:color_column},2000);

You can do:

$(this).siblings('p').add(this).animate({color:color_column},2000);

See the documentation for .add().

0

精彩评论

暂无评论...
验证码 换一张
取 消