使用jquery获取元素的-webkit-transform的值 [英] Get the value of -webkit-transform of an element with jquery

查看:702
本文介绍了使用jquery获取元素的-webkit-transform的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $(# thediv)。css( -  webkit-transform,translate(-770px,0px)); 

稍后在脚本中我想得到这样的转换值:

  $(#thediv)。css( -  webkit-transform); 

它返回如下矩阵: matrix(1,0,0,1, 770,0)



我不知道如何获得此矩阵的第5个值(-770)...



有任何建议吗?
谢谢!

解决方案

您的矩阵是一个4x4变换矩阵:





对应于 v x 。要提取它,构造一个 WebkitCSSMatrix 对象:

  var style = window .getComputedStyle($('#thediv')。get(0)); //需要DOM对象
var matrix = new WebKitCSSMatrix(style.webkitTransform);

console.log(matrix.m41); // -770


I'm manipulating a div with the new cool css3 way of doing a transform like this:

$("#thediv").css("-webkit-transform","translate(-770px, 0px)");

Later on in the script I thought to get the value of the transform like this:

$("#thediv").css("-webkit-transform");

It returns a matrix like this: matrix(1, 0, 0, 1, -770, 0)

What I can't figure out is how to get the 5th value (-770) of this matrix...

Any suggestions? Thanks!

解决方案

Your matrix is a 4x4 transformation matrix:

The -770 corresponds to the vx. To extract it, construct a WebkitCSSMatrix object:

var style = window.getComputedStyle($('#thediv').get(0));  // Need the DOM object
var matrix = new WebKitCSSMatrix(style.webkitTransform);

console.log(matrix.m41);  // -770

这篇关于使用jquery获取元素的-webkit-transform的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆