[英]jquery running same function on multiple elements relatives to 'This'
$(".column a").mouseenter(function() {
var color_column=$(this).closest('.column').children('.coloured-strip').css('color');
$(this).siblings('p').animate({color:color_column},2000);
$(this).animate({color:color_column},2000);
});
There's any way I can group the two animate functions into one since they're identical? 因为它们是相同的,所以有什么方法可以将两个动画功能组合为一个?
thanks luca 谢谢卢卡
当然,只需使用.add()
:
$(this).siblings('p').add(this).animate({color:color_column},2000);
您可以使用andSelf()
方法:
$(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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.