Trying to animate background color on page load but it only wor开发者_如何学Goks when I actually click the element. I am using the colors plugin.
$(window).load(function () {
$(".hilite").toggle(function() {
$(this).animate({ backgroundColor: "yellow" }, 1000);
},function() {
$(this).animate({ backgroundColor: "#FFF2A8" }, 500);
});
})
<span class="hilite">THIS should change background COLOR</span>
As far as I understand, you are trying to do this:
$(document).ready(function(){
$('.hilite').css({'background-color', 'yellow'});
$('.hilite').animate({ 'background-color' : "#FFF2A8" }, 1000);
});
or this:
$(document).ready(function(){
$('body').animate({ 'background-color': "#FFF2A8" }, 1000);
});
You are using no plugin that I can see.
toggle()
works on click.
精彩评论