使用 jQuery 检测跨浏览器的 CSS 转换变化

发布于 2024-12-22 08:52:50 字数 477 浏览 1 评论 0原文

我需要使用 jQuery 检测 CSS 变换属性是否已更改。在 firebug 中,我希望检测更改的 CSS 属性呈现如下:

-moz-transform:translate(-0px, 0px)

我需要检测这是否已更改为另一个像素属性。例如:

-moz-transform:translate(-100px, 0px)

更多详细信息:

最终,我尝试在以下演示中检测单击和拖动之间的情况。

http://cubiq.org/dropbox/iscroll4/examples/carousel/

我想我可以在当前的变换属性上查询mouseup,如果它保持不变,则为单击,或者如果变换属性发生更改,则为拖动。

I need to detect if the CSS transform property has changed using jQuery. In firebug the CSS property i'm looking to detect changes on is rendered like this:

-moz-transform: translate(-0px, 0px)

I need to detect whether this has changed to another pixel property. For example:

-moz-transform: translate(-100px, 0px)

More details:

Ultimately I'm trying to detect between a click and a drag on the following demo.

http://cubiq.org/dropbox/iscroll4/examples/carousel/

I figured that I could query mouseup on the current transform property and if it remained the same that it was a click or if the transform property changed it would be a drag.

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

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

发布评论

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

评论(1

ぽ尐不点ル 2024-12-29 08:52:50

您可以使用 Modernizr 创建供应商前缀,然后可以使用 .split() 分解 .css() 的输出并获取所需的值。

以下是获取正确前缀属性的方法:

if (Modernizr.csstransforms3d) {
    trans_key = Modernizr.prefixed('transform').replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');

} else if (Modernizr.csstransforms) {
    trans_key = Modernizr.prefixed('transform').replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
}

来源:http://www.modernizr。 com/docs/#prefixed

然后你可以使用 .css() 来获取 -vender-transform 属性:

var matrix = $('#element-id').css(trans_key);//output = matrix(1, 0, 0, 1, 100px, 0px)

最后你可以 <代码>.split() matrix 值转换为可用的东西:

var data = matrix.replace(')', '').split(',');//data[4]='100px', data[5]='0px'

这是一个演示:http://jsfiddle.net/7Yz8B/

You can use Modernizr to create the vender prefix and then you can use .split() to break apart the output from .css() and get the desired values.

Here is a method of getting the properly prefixed property:

if (Modernizr.csstransforms3d) {
    trans_key = Modernizr.prefixed('transform').replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');

} else if (Modernizr.csstransforms) {
    trans_key = Modernizr.prefixed('transform').replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
}

Source: http://www.modernizr.com/docs/#prefixed

Then you can use .css() to get the -vender-transform property:

var matrix = $('#element-id').css(trans_key);//output = matrix(1, 0, 0, 1, 100px, 0px)

Then finally you can .split() the matrix value into something useable:

var data = matrix.replace(')', '').split(',');//data[4]='100px', data[5]='0px'

Here is a demo: http://jsfiddle.net/7Yz8B/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文