2011-12-02 24 views
3

我想單獨調整元素的大小和位置,以便能夠使用jQuery的stop()函數爲一個屬性清除隊列,但不能清除其他屬性。我只是動畫widthleft屬性。我可以使用jQuery獨立地動畫屬性嗎?

有沒有辦法完成這個?

+0

你的意思是「清除所有‘左’動畫的隊列,但允許‘寬度’」或你的意思是,只有當你做一個或另一個清除隊列? – Mathletics

+0

我的意思是清除任何「左」動畫的隊列,但允許「寬度」繼續。基本上,就像有兩個單獨的隊列。 – Koviko

回答

3

你需要使用jquery 1.7,但是這可以完成。

http://jsfiddle.net/jRawX/16/

由於1.7,你可以傳遞一個字符串作爲queue參數。這會將動畫隊列排列在命名隊列中而不是fx隊列中。然後,當你呼叫停止時,你可以傳遞相同的隊列名稱。

$(function() { 
 

 
    $("#stopTop").click(function() { 
 
     $("#t1").stop("topQueue", true); 
 
    }); 
 

 
    $("#stopLeft").click(function() { 
 
     $("#t1").stop("leftQueue", true); 
 
    }); 
 

 
    $('#t1').animate({ 
 
     left: 100 
 
    }, { 
 
     duration: 10000, 
 
     queue: "leftQueue" 
 
    }).animate({ 
 
     left: 600 
 
    }, { 
 
     duration: 10000, 
 
     queue: "leftQueue" 
 
    }).animate({ 
 
     top: 100 
 
    }, { 
 
     duration: 10000, 
 
     queue: "topQueue" 
 
    }).animate({ 
 
     top: 600 
 
    }, { 
 
     duration: 10000, 
 
     queue: "topQueue" 
 
    }).dequeue("topQueue").dequeue("leftQueue"); 
 
})
.tester { 
 
     background:red; 
 
     width: 100px; 
 
     height: 100px; 
 
     left: 400px; 
 
     top: 300px; 
 
     position: absolute; 
 
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
 
<div class="tester" id="t1"></div> 
 

 
<button id="stopTop">Stop Top</button> 
 
<button id="stopLeft">Stop Left</button>

+0

太棒了!謝謝。 :) – Koviko

相關問題