我当前有一个对象,volumeSlider,它受到其他两个控件事件的影响:
var volumeSlider = $('#VolumeSlider');
$('#MuteButton').on('mouseenter', function() {
volumeSlider.fadeIn('fast');
}
$('#Controls').on('mouseleave', function() {
volumeSlider.fadeOut('fast');
}
我想反转它,以便volumeSlider“监听”MuteButton 和控件上的事件,而不是被告知响应它们。这可能吗?像这样的东西:
//Pseudo-Code:
volumeSlider.on('#MuteButton.mouseenter'){
this.fadeIn('fast');
}.on('#Controls.mouseleave'){
this.fadeOut('fast');
}
是 jQuery 的 http://api.jquery.com/bind/这里有用吗?
最佳答案
这里有一个建议:
volumeSlider.on('dosomething', function(e) {
$(this).fadeIn('fast');
});
$('#MuteButton').on('mouseenter', function(e) {
volumeSlider.trigger('dosomething');
}
关于javascript - 反转对象与其他对象事件的耦合方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11055657/