2015-01-13 72 views
0

我正在使用jQuery動畫中的步驟來動畫CSS轉換屬性。 什麼時間限制,我保留動畫功能,沒有考慮到。 我的代碼是這樣的在jQuery動畫功能中的步驟

$('#instructions').animate({now:'+=50'},{ 
    step: function(now) { 
     $(this).css('transform','rotate('+now+'deg)'), duration:'slow' 
    } 
},50000); 

我在這裏我的旋轉格約50度與50000ms的時間跨度,但它不是採取這些50000ms。 我能做些什麼來創造那個時間跨度。 在此先感謝。

這是我的HTML。

我正在使div旋轉像擺鐘。

<html><head> 


<style type="text/css"> 

.subMenu { 
width: 143px; 
height: 80px; 
border-bottom: 1px solid white; 
line-height: 110px; 
text-align: center; 
font-size: 27px; 
} 
#line:before{ 
border-left: 1px solid white; 
border-right: 1px solid white; 
border-bottom: 49px solid white; 
content: ""; 
position: absolute; 
top: -50px; 
left: 59px; 
} 
</style> 
<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
$('#instructions').animate({ now: '+=50' }, { 
    step: function(now,fx) { 
     $(this).css('transform','rotate('+now+'deg)'); 
    } 
},50); 

$('#instructions').animate({ now: '-=100' }, { 
    step: function(now,fx) { 
     $(this).css('transform','rotate('+now+'deg)'); 
    } 
},50); 
$('#instructions').animate({ now: '+=50' }, { 
    step: function(now,fx) { 
     $(this).css('transform','rotate('+now+'deg)'); 
    } 
},50); 

}); 


</script> 
</head> 
<body> 

<div id="menu" style=" 
    width: 43px; 
    height: 34px; 
    position: absolute; 
    margin: 5px; 
    left: 188px; 
    box-shadow: 4px 4px 13px white; 
    border: 1px solid black; 
    line-height: 28px; 
    font-weight: bold; 
    text-align: center; 
" >Menu</div> 
<div style=" 
    transform: rotate(0deg) scale(1, 1); display: block; 
    width: 1px; 
    height: 1px; 
    position: absolute; 
    background: white; 
    left: 216px; 
    top: 48px; 
" id="instructions"><div id="line" style=" 
    width: 101px; height: 73px; position: absolute; top: 50px; left: -59px; font-family: cursive; box-shadow: 3px 3px 23px 0px white; padding: 12px; background: white; 
"> 
    Click Here to Show/Hide the Menu</div></div> 

<div id="section1" style=" 
    height: 556px; 
    width: 230px; 
    background: rgb(106, 163, 226); 
    float: left; 
    border: solid black ; 
    border-width: 1px 0px 1px 1px; 
    /* display: none; */ 
"><div style=" 
    height: 200px; 
    width: 180px; 
    margin-left: 40px; 
    margin-top: 165px; 
    color: white; 
    cursor:pointer; 
"><div class="subMenu" style="color:black;" id="uploadMenu">UPLOAD</div> 
<div class="subMenu" id="viewMenu">VIEW</div> 
    <div class="subMenu" id="reportMenu">REPORT</div></div> 
</div> 
<div id="section2"> 

    <div id="main_content" style=" 
    height: 556px; 
    width: 1080px; 
    background:rgb(6,206, 151); 
    border: solid black; 

    border-width:1px 1px 1px 0px ; 
    float: left; 
"> 

</div> 



</div> 



</body></html> 

jsfiddle.net

+0

發表您的目標HTML(A [小提琴](http://jsfiddle.net/)將是巨大的) – chiapa

+0

@ chiapa,我已經發布在問題中的目標HTML,對不起,我不能給你一個小提琴 – Jayababu

回答

1

您正在使用.animate與不正確的參數 - 你試圖傳遞一個durationoptions不存在。你打電話或者使用:

  • .animate(properties [, duration ] [, easing ] [, complete ])
  • .animate(properties, options)

如果使用第二個版本,那麼你需要設置options對象內部duration財產。

這工作:

$(document).ready(function(){ 
 
    var animDuration = 1000; 
 

 
    $('#instructions').animate({ now: '+=50' }, { 
 
     duration:animDuration, 
 
     step: function(now,fx) { 
 
      $(this).css('transform','rotate('+now+'deg)'); 
 
     } 
 
    }); 
 

 
    $('#instructions').animate({ now: '-=100' }, { 
 
     duration:animDuration, 
 
     step: function(now,fx) { 
 
      $(this).css('transform','rotate('+now+'deg)'); 
 
     } 
 
    }); 
 

 
    $('#instructions').animate({ now: '+=50' }, { 
 
     duration:animDuration, 
 
     step: function(now,fx) { 
 
      $(this).css('transform','rotate('+now+'deg)'); 
 
     } 
 
    }); 
 

 
})
.subMenu { 
 
    width: 143px; 
 
    height: 80px; 
 
    border-bottom: 1px solid white; 
 
    line-height: 110px; 
 
    text-align: center; 
 
    font-size: 27px; 
 
} 
 
#line:before { 
 
    border-left: 1px solid white; 
 
    border-right: 1px solid white; 
 
    border-bottom: 49px solid white; 
 
    content:""; 
 
    position: absolute; 
 
    top: -50px; 
 
    left: 59px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
 
<div id="menu" style=" 
 
    width: 43px; 
 
    height: 34px; 
 
    position: absolute; 
 
    margin: 5px; 
 
    left: 188px; 
 
    box-shadow: 4px 4px 13px white; 
 
    border: 1px solid black; 
 
    line-height: 28px; 
 
    font-weight: bold; 
 
    text-align: center; 
 
">Menu</div> 
 
<div style=" 
 
    transform: rotate(0deg) scale(1, 1); display: block; 
 
    width: 1px; 
 
    height: 1px; 
 
    position: absolute; 
 
    background: white; 
 
    left: 216px; 
 
    top: 48px; 
 
" id="instructions"> 
 
    <div id="line" style=" 
 
    width: 101px; height: 73px; position: absolute; top: 50px; left: -59px; font-family: cursive; box-shadow: 3px 3px 23px 0px white; padding: 12px; background: white; 
 
">Click Here to Show/Hide the Menu</div> 
 
</div> 
 
<div id="section1" style=" 
 
    height: 556px; 
 
    width: 230px; 
 
    background: rgb(106, 163, 226); 
 
    float: left; 
 
    border: solid black ; 
 
    border-width: 1px 0px 1px 1px; 
 
    /* display: none; */ 
 
"> 
 
    <div style=" 
 
    height: 200px; 
 
    width: 180px; 
 
    margin-left: 40px; 
 
    margin-top: 165px; 
 
    color: white; 
 
    cursor:pointer; 
 
"> 
 
     <div class="subMenu" style="color:black;" id="uploadMenu">UPLOAD</div> 
 
     <div class="subMenu" id="viewMenu">VIEW</div> 
 
     <div class="subMenu" id="reportMenu">REPORT</div> 
 
    </div> 
 
</div> 
 
<div id="section2"> 
 
    <div id="main_content" style=" 
 
    height: 556px; 
 
    width: 1080px; 
 
    background:rgb(6,206, 151); 
 
    border: solid black; 
 

 
    border-width:1px 1px 1px 0px ; 
 
    float: left; 
 
"></div> 
 
</div>

+0

值得注意的是,因爲OP使用'step'回調來做動畫,如果動畫在jQuery中被全局禁用,元素將不會' t最終會落到最後的位置。這裏沒有問題,因爲最終的位置回到了它開始的地方。 –