简体   繁体   English

JQuery在Class中设置CSS Transform,Translate Properties

[英]JQuery set CSS Transform, Translate Properties in Class

I cannot seem to set the CSS properties of transform using Jquery. 我似乎无法使用Jquery设置转换的CSS属性。

Here is my Code: https://jsfiddle.net/op7Lsvdp/ 这是我的代码: https//jsfiddle.net/op7Lsvdp/

These are the two methods I have unsuccessfully tried. 这些是我尝试过的两种方法。

$('.slideToCart').css({
  '-webkit-transform' : 'translate(left, top)',
  '-moz-transform'    : 'translate(left, top)',
  '-ms-transform'     : 'translate(left, top)',
  '-o-transform'      : 'translate(left, top)',
  'transform'         : 'translate(left, top)'
});

$('.slideToCart').css('transform', 'translate(50px, 50px)');
$('.slideToCart').css('-webkit-transform', 'translate(50px, 50px)');

Thank You, 谢谢,

I think important thing about css method is that it is not changing your class property, but it is changing style property of object that you are calling it on. 我认为关于css方法的重要一点是它不会改变你的属性,但是它正在改变你调用它的对象的style属性。

This will do: 这样做:

$( document ).ready(function() {
    $('.buttonHolder').click(function(){
        $(this).find("span").toggleClass('fadeText');
        var button = $(this).find("button");
        button.toggleClass('shrink');

        var position = $('.target').position();
        var left = position.left + 'px';
        var top = position.top + 'px';

        var buttonHolder = $(this);

        setTimeout(function() {
            buttonHolder.css({'transform' : 'translate(' + left +', ' + top + ')'});
        }, 1000);
    });
});

You're adding styles to .slideToCart elements, but there are none! 你正在为.slideToCart元素添加样式,但没有! See the console log: 查看控制台日志:

https://jsfiddle.net/op7Lsvdp/2/ https://jsfiddle.net/op7Lsvdp/2/

You're adding those classes after click on .buttonHolder , so maybe that's the time you want to add the .css 你点击.buttonHolder后添加这些类,所以也许你想要添加.css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM