2017-04-24 35 views
0

我用貓頭鷹輸送帶2 我想改造貓頭鷹舞臺上,以權當鼠標懸停。 它在CSS中工作。變換不工作與jQuery

.owl-stage:hover { 
    -webkit-transform: translate3d(-1280px, 0, 0) !important; 
    transform: translate3d(-1280px, 0, 0) !important; 
    transition: 450ms transform, 450ms -webkit-transform; 
} 

由於translate3d值(-1280px)被動態更改爲貓頭鷹傳送帶。 我需要檢查與jQuery。

$('.owl-stage').hover(function() { 
     console.log('stage overed'); 

     normalanimation = $(this).css('transform').split(',')[4]; 
     var animation = parseInt(normalanimation) + (-112); 
     console.log(animation); 
     //$(this).transition({ x: '-40px' }); 
     $(this).css({ "transform": "translate3d(" +animation+ "px, 0, 0) !important;", "transition": "transform 450ms"}); 
    }); 

我用了很多其他的方式,如風格atrr。但沒有運氣。 或者jQuery不支持css轉換?

+0

你能嘗試使用撥動類,而不是內嵌樣式? http://api.jquery.com/toggleclass/ –

+0

什麼'動畫'在控制檯打印出來?你在DOM屬性中看到了什麼? – Justinas

+0

@SyedFarhan我不能使用切換類,因爲當我點擊導航按鈕或拖動項目時,translate3d值是由owl傳送帶動態設置的。 – taymyinl

回答

0

你不能使用.css()方法和"!important" jQuery只是不正確地理解它,所以它被忽略。使用

嘗試更新.attr()方法,而不是

$(this).attr("style", "transform:translate3d(" +animation+ "px, 0, 0)!important; transition:transform 450ms"); 
+0

謝謝。但它會覆蓋貓頭鷹階段的原始屬性。是否有可能只修改變換值? – taymyinl

+0

好的,首先得到現有的樣式並追加新的樣式。 例如:$(this).attr(「style」,$(this).attr(「style」)+「; transform:translate3d(」+ animation +「px,0,0)!important; transition:transform 450ms」 ); – partypete25

+0

感謝您的解決方案。有用。 – taymyinl