Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

javascript - Get translate3d values of a div?

Say a div has this applied to it:

-webkit-transform: translate3d(0px, -200px, 0px)

How could I retrieve those values with jQuery?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you change the accepted answer's match() pattern to this it adds support for negative numbers:

$(el).css('-webkit-transform').match(/matrix(?:(3d)(-{0,1}d+(?:, -{0,1}d+)*(?:, (-{0,1}d+))(?:, (-{0,1}d+))(?:, (-{0,1}d+)), -{0,1}d+)|(-{0,1}d+(?:, -{0,1}d+)*(?:, (-{0,1}d+))(?:, (-{0,1}d+))))/)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...