Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用clientX和clientY时,如何通过jQuery添加translate3d?_Jquery - Fatal编程技术网

在使用clientX和clientY时,如何通过jQuery添加translate3d?

在使用clientX和clientY时,如何通过jQuery添加translate3d?,jquery,Jquery,我这里有一个jQuery的片段,其中添加了CSS:transform:translate()。我想知道是否可以使用transform:translate3d()。我该怎么写呢 $(document).mousemove(function(e) { $circle.css({ transform: 'translate(' + (e.clientX - half_cHeight) + 'px, ' + (e.clientY - half_cWidth) + 'px)' })

我这里有一个jQuery的片段,其中添加了CSS:
transform:translate()
。我想知道是否可以使用
transform:translate3d()
。我该怎么写呢

$(document).mousemove(function(e) {
   $circle.css({
      transform: 'translate(' + (e.clientX - half_cHeight) + 'px, ' + (e.clientY - half_cWidth) + 'px)'
   });
});
我已经尝试了下面的猜测,但我不确定最后该放什么,也不起作用

transform: 'translate3d(' + (e.clientX - half_cHeight) + 'px, ' + (e.clientY - half_cWidth) + 'px, ' + 'px )'

有人能帮我正确地执行此操作吗?

您正在传递一个无法识别的单位(
px
,无值)作为translate3d的第三个参数,该参数采用3个参数x y z,由其属性名称识别

transform: 'translate3d(' + (e.clientX - half_cHeight) + 'px, ' + (e.clientY - half_cWidth) + 'px, 0px)'

嗨,克洛伊,谢谢你的回答。我已经试过了,它似乎对我要移动的物体没有任何影响。这是一个JSFiddle-