2016-07-21 61 views
3

我正在嘗試使圖像上的邊距都爲自動。我做這個:jQuery動畫失敗,保證金 - 左/右自動

$('#headerImg').delay(100).animate({ 
    "margin-left": "auto", 
    "margin-right": "auto" 
}, 650, function() { 
    //not important 
}); 

,但它不工作。但它確實工作,如果我這樣做:

$('#headerImg').css({"margin-left":"auto","margin-right":"auto"}); 

我的問題是,它爲什麼不工作?是否有任何可能的方法讓它再次正常工作,還是我需要提出一個解決這個問題的方法?

任何幫助,非常感謝。

+0

的可能的複製[jQuery的:動畫邊距爲自動(http://stackoverflow.com/questions/4511036/jquery-animate-margins-to-auto) – smoksnes

+0

請嘗試我的答案並讓我知道,謝謝 –

回答

0

嘗試以下操作:

$('#headerImg').delay(100).animate({ 
    marginLeft: "auto", 
    marginRight: "auto" 
}, 650, function() { 
    //not important 
});