我正在使用 owl carousel 2。 我想在鼠标结束时将 Owl-Stage 转换为右侧。 它适用于 CSS。
.owl-stage:hover {
-webkit-transform: translate3d(-1280px, 0, 0) !important;
transform: translate3d(-1280px, 0, 0) !important;
transition: 450ms transform, 450ms -webkit-transform;
}
由于 translate3d 值 (-1280px) 由 Owl Carousel 动态更改。 我需要使用 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 转换?
最佳答案
您不能使用 .css()
方法和 "!important"
jQuery 无法正确理解它,所以它会被忽略。
尝试使用 .attr() 方法更新
$(this).attr("style", "transform:translate3d(" +animation+ "px, 0, 0)!important; transition:transform 450ms");
关于jquery - 转换不适用于 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43580583/