我在背景图像上应用了淡出效果。如何在 mouseout 上缓慢应用回原始样式?
jsfiddle:http://jsfiddle.net/KevinOrin/H6Q3J/
jQuery('.square-section').mouseover(function(){
jQuery(this).fadeTo('slow',0.3, function(){
jQuery(this).css('background-image', 'url(' + $img + ')');
}).fadeTo('slow',1);
});
最佳答案
您首先没有使用 $img 变量
..所以首先不需要回调函数..
如果您要完全更改图像,回调函数可能会在此处提供帮助。
jQuery('.square-section').hover(function(){
jQuery(this).fadeTo('slow',0.3);
}, function() {
jQuery(this).fadeTo('slow',1);
});
如果你想交换 2 个不同的图像你可以试试这个方法
jQuery('.square-section').hover(function(){
jQuery(this).fadeTo('slow', 0.3, function() {
jQuery('.square', this).removeClass('square-chess').addClass('square-chart');
jQuery(this).fadeTo('fast', 1);
});
}, function() {
jQuery(this).fadeTo('fast', 0.3, function() {
jQuery('.square', this).removeClass('square-chart').addClass('square-chess');
jQuery(this).fadeTo('fast', 1);
});
});
jQuery('.square-section').hover(function () {
jQuery('.square', this).removeClass('square-chess').addClass('square-chart');
}, function () {
jQuery('.square', this).removeClass('square-chart').addClass('square-chess');
});
关于javascript - 如何在 jQuery mouseout 上应用原始样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16551431/