Get 'translateX' position in jQuery

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

This code sets the translateX position:

 var pos = -500px;  $(.slide).css('-webkit-transform',  "translateX(" + pos+ "px)"); 

but, the following code does not get the translateX position:

 var currTrans = $(".slide").css('-webkit-transform', "translateX()"); 

Why? What is the correct way to get the value then?

回答1:

Try this,

var pos = -500;  $('.slide').css('-webkit-transform',  'translateX(' + pos+ 'px)');  var currTrans = $('.slide').css('-webkit-transform').split(/[()]/)[1]; var posx = currTrans.split(',')[4]; 

Upadate:

Demo link jsfiddle



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!