按时间触发事件

时间:2015-02-12 04:37:10

标签: jquery css css-transitions

我想触发一个元素来完成css转换;但是,我不想使用任何物理触发器,例如悬停或点击。我想在特定时间开始转换,然后以特定时间间隔重复。这可以使用jquery完成。

2 个答案:

答案 0 :(得分:0)

您可以使用setInterval并在特定时间范围后添加转换类,并在特定时间范围后删除它。

请看: - http://jsbin.com/jemotexono/1/edit?html,css,js,output

编写集间隔的最简单方法是: -

  setInterval(function(){
    //Your code goes here 

  },2000); //specify the time in milliseconds

答案 1 :(得分:-1)

Try out the sample code 

**HTML**
<div></div>

**CSS**
div {
    width: 100px;
    height: 100px;
    background: green;
    -webkit-transition: width 1s; /* For Safari 3.1 to 6.0 */
    transition: width 1s;
}

**Java Script**
$(document).ready(function(){
    var width = 100;
    //set the specific time to trigger
    setTimeout(function(){ trigger(); }, 1000);
    //function which perform the tranisition repeatedly
                  function trigger(){      
    setInterval(function(){
        width = width +5;
        $("div").css("width",width); 
                          }, 1000);

}                            
});    
相关问题