通过 js 组合 css3 转换

发布于 2024-12-09 17:55:50 字数 913 浏览 0 评论 0 原文

请问有没有办法随着时间的推移结合更多的 CSS3 转换? 例如,当我设置这个

$bgWrapper.css({
 '-webkit-transform' : ' scale3d(' + currScale + ', '+ currScale +', 1)'
});

然后在几分钟内

$bgWrapper.css({
'-webkit-transform' : 'translate3d('+ ((currCoords[0])/currScale) +'px, '+ ((currCoords[1])/currScale) +'px, 0px) '
});

我遇到了一个问题。第一个转换被第二个转换覆盖,但这就是我绝对不希望发生的事情。 所以我观察到我可以组合这些值,这样我就可以暂时存储旧的值并执行此操作

var tmpTransform = $bgWrapper.css('-webkit-transform');
$bgWrapper.css({
'-webkit-transform' : ''+ tmpTransform +'translate3d('+ ((currCoords[0])/currScale) +'px, '+ ((currCoords[1])/currScale) +'px, 0px) '
});

但即使这不正确,重复调用也存在问题..

那么有没有一种方法可以通过javascript获取css3比例的准确值?有没有办法通过js获取CSS3翻译的准确值? 目前我只得到具有这些值的矩阵,当然我可以解析它,但我希望有更好的解决方案。

最后..我想-webkit-transform:matrix(...)在iPad上不是硬件加速的,所以唯一的方法是matrix3d?正确地结合所有这些转换没有问题。

非常感谢,希望你理解我的问题:)

please is there a way how to combine more CSS3 transforms over the time?
For example when I set this

$bgWrapper.css({
 '-webkit-transform' : ' scale3d(' + currScale + ', '+ currScale +', 1)'
});

And then in few moments this

$bgWrapper.css({
'-webkit-transform' : 'translate3d('+ ((currCoords[0])/currScale) +'px, '+ ((currCoords[1])/currScale) +'px, 0px) '
});

I get a problem. First transform is overriden with the second one, but thats what I definitely don't want to happen.
So I observed I can combine these values,so I can temporarily store the old one and the do this

var tmpTransform = $bgWrapper.css('-webkit-transform');
$bgWrapper.css({
'-webkit-transform' : ''+ tmpTransform +'translate3d('+ ((currCoords[0])/currScale) +'px, '+ ((currCoords[1])/currScale) +'px, 0px) '
});

But even thats not correct, there are problems with repeating calls..

So is there a way how to obtain exact value of css3 scale vie javascript? Is there a way how to get exact value of CSS3 translate via js?
Currently I am only getting matrix with these values, off course I can parse it, but I hope there is better solution.

And finally..I suppose that -webkit-transform: matrix(...) is not hardware accelerared on iPad, so only way is matrix3d? to correctly combine all these transformation without problems..

Thanks a lot, hope you understand my questions:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

丿*梦醉红颜 2024-12-16 17:55:50

您需要操作矩阵才能完成您想做的事情:

   var transform = new  WebKitCSSMatrix(window.getComputedStyle(element).webkitTransform);
   transform = transform.rotateAxisAngle(0,0,0,45)
   element.style.webkitTransform = transform;

操纵WebkitCSSMatrix 是:

.multiply()
.inverse()
.translate()
.scale()
.rotate()
.rotateAxisAngle()
.skewX()
.skewY()

您可以在此处查看演示:

http://jsfiddle.net/ 6jGaA/

You need to manipulate the matrix in order do accomplish what you want to do:

   var transform = new  WebKitCSSMatrix(window.getComputedStyle(element).webkitTransform);
   transform = transform.rotateAxisAngle(0,0,0,45)
   element.style.webkitTransform = transform;

The methods for manipulating WebkitCSSMatrix are:

.multiply()
.inverse()
.translate()
.scale()
.rotate()
.rotateAxisAngle()
.skewX()
.skewY()

And you can view a demo here:

http://jsfiddle.net/6jGaA/

时光匆匆的小流年 2024-12-16 17:55:50

我是网页设计新手,但并不是 Google 新手。

要组合转换,您必须将所有转换放在同一行代码中。

本文对此进行了解释:http://www.htmlgoodies.com/beyond/css/css3-features-every-web-designer-is-excited-about-skewed-rotated-and-scaled-text.html

我所说的这段话就在底部附近。

组合转换

CSS 转换本身很有用,但当您将它们组合在一起并获得显着结果时,它们的真正威力才会显现出来。每当您组合它们时,请记住您必须在一行中定义所有转换。这是示例语法:

#rotate-skew-scale-translate {
transform:skew(30deg) scale(1.1,1.1) rotate(40deg) translate(10px, 20px);
}

I am new to web design but am no novice Googler.

To combine transformations, you have to put all the transformations on the same line of code.

This article explains it: http://www.htmlgoodies.com/beyond/css/css3-features-every-web-designer-is-excited-about-skewed-rotated-and-scaled-text.html.

The passage I am talking about is near the bottom.

Combining the Transformations

CSS transforms by themselves are useful, but their real power is unveiled when you combine them together and get remarkable results. Whenever you are combining them, remember that you have to define all the transforms in one line. Here is the sample syntax:

#rotate-skew-scale-translate {
transform:skew(30deg) scale(1.1,1.1) rotate(40deg) translate(10px, 20px);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文