开发者

jQuery animate colors plugin only works when clicked?

开发者 https://www.devze.com 2023-04-07 07:28 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消