Jquery 回到原来的颜色
我想为不同div的背景色设置动画。 当鼠标离开div时,是否可以使用原始颜色Jquery 回到原来的颜色,jquery,css,animation,Jquery,Css,Animation,我想为不同div的背景色设置动画。 当鼠标离开div时,是否可以使用原始颜色 您只需将BG颜色保存到元素中,然后再进行更改。在这里,我将其保存在数据属性中: $(".color").hover(function(){ $(this).animate({ backgroundColor: 'red' }); },function(){ $(this).animate({ backgroundColor: '' }); }); 您只需将BG颜色保存到元素中,然后再进行更改。在这里,我将其保存在
$(".color").hover(function(){
$(this).animate({ backgroundColor: 'red' });
},function(){
$(this).animate({ backgroundColor: '' });
});
您只需将BG颜色保存到元素中,然后再进行更改。在这里,我将其保存在数据属性中:
$(".color").hover(function(){
$(this).animate({ backgroundColor: 'red' });
},function(){
$(this).animate({ backgroundColor: '' });
});
您可以执行以下操作:
$(".color").hover(function(){
var $this = $(this);
$this.data('bg-color', $this.css('backgroundColor'));
$this.animate({ backgroundColor: 'red' });
},function(){
var $this = $(this);
$(this).animate({ backgroundColor: $this.data('bg-color') });
});
该函数包装器用于防止创建全局原始变量。如果需要,您可以将其删除。您可以执行以下操作:
$(".color").hover(function(){
var $this = $(this);
$this.data('bg-color', $this.css('backgroundColor'));
$this.animate({ backgroundColor: 'red' });
},function(){
var $this = $(this);
$(this).animate({ backgroundColor: $this.data('bg-color') });
});
该函数包装器用于防止创建全局原始变量。如果需要,您可以删除它。您只能通过css来完成
(function ()
var original;
$(".color").hover(function () {
original = $(this).css('background-color');
$(this).animate({
backgroundColor: 'red'
});
}, function () {
$(this).animate({
backgroundColor: original
});
});
());
你只能通过css来实现
(function ()
var original;
$(".color").hover(function () {
original = $(this).css('background-color');
$(this).animate({
backgroundColor: 'red'
});
}, function () {
$(this).animate({
backgroundColor: original
});
});
());
为什么不使用CSS3?为什么不使用CSS3?