jquery - 转换不适用于 jQuery

标签 jquery css owl-carousel

我正在使用 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/

相关文章:

jquery - 如何在完整日历jquery中获取当前显示的日期范围

jquery - 如何向 jQuery.Ajax 成功函数返回多个值

css - 如何在 Angular 选择新列表项时删除先前选择的列表项的事件类

javascript - 我怎样才能将 .owl-pagination 移动到主猫头鹰包装器之外? Owl Carousel 2

javascript - 单击#-links 时避免窗口跳到顶部

javascript - 将 HREF 替换为标签之间的内容(使用电子邮件表达式)

css - 更改禁用标签上的光标

css - angularjs 仅对整个集合中的可见对象进行交替着色

javascript - 为多个 Owl Carousel 创建计数器

javascript - Chrome 中未应用 Owl Carousel 动画