2017-04-24 85 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