English 中文(简体)
我如何在两种背景颜色之间轮流?
原标题:How can I alternate between two background colors?

我建造一个日历,其中一项要求是规定背景物色体资产,以强调某些日子。

然而,有一天需要两种不同的颜色:例如,假日发生。

是否有办法在两种不同的背景颜色之间轮流? 我们再次使用 j,我审视了周期的gin,但这似乎完全超出了我所需要的技能。

这将一劳永逸地循环,但我喜欢继续这样做:

$(".toggleBG").animate({ backgroundColor: "#FFFF66" }, 2000, function() {
    $(".toggleBG").animate({ backgroundColor: "#99CCFF" }, 2000)
});
最佳回答

这应当做到:

var animate1, animate2;
var elem = $(".toggleBG");

animate1 = function() {
    elem.animate({ backgroundColor: "#FFFF66" }, 2000, animate2)
}
animate2 = function() {
    elem.animate({ backgroundColor: "#99CCFF" }, 2000, animate1)
}

animate1();

每个职能部门将另一个职能作为向animate发出的提示。


阻止消沉的最容易的方法是:

animate1 = animate2 = undefined
问题回答
function toggleBg(){
    if($( .toggleBG ).css( backgroundColor ) ==  #FFFF66 ){
        $( .toggleBG ).css( backgroundColor ,  #99CCFF );
    }else{
        $( .toggleBG ).css( backgroundColor ,  #FFFF66 );
    }
    setTimeout(toggleBg, 2000);
}
$(function(){
    toggleBg();
});

仅靠jquery UI图书馆支持彩色改动,因此,当你从下载jQueryUI图书馆时,它就应当工作。

var changeColors = setInterval(function() { 
     $(".toggleBG").toggleClass( color2 );
}, 2000);

然后,为每个背景制定特别安全规则:

div.color1 { 
     background-color: #FFFF66;
     -moz-transition: all 1s ease-in-out;
     -webkit-transition: all 1s ease-in-out;
     transition: all 1s ease-in-out;
}
div.color1.color2 { background-color: #99CCFF; }

过渡将使彩色变化顺利进行,而不是“鞭.”,至少是支持这种变化的较新的浏览器。

或许还有其他办法可以做到这一点,但你可以利用停职职能,使守则得以继续:

function flip() {
    $(".toggleBG").animate( 
    { backgroundColor: "#FFFF66" }, 2000, function() {
    $(".toggleBG").animate({ backgroundColor: "#99CCFF" }, 2000) 
    });
    setTimeout( flip(), 1 );
}




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...

热门标签