关于IE、FF 中的event.clientX、event.clientY

         在IE中,event为全局变量,可以直接使用,但是在FF中 event则为局部变量,要把它作为参数传过来才可以使用!例如:

function  mousedown(event){//FF下

     var x=event.clientX;

}

        在ie下则可以直接在任何位置  var x=event.clientX;

        兼容的方法是:使用event.clientX的函数中传一个参数进来,并在函数内添加以下语句:event=event||window.event---其中event为函数传进来的参数,例如:

function  mousedown(event){

     event=event||window.event;

     var x=event.clientX;

}

     另外,IE下判断鼠标、键盘按键的方法为:event.button 、event.keycode,FF 下为 event.which。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
import * as THREE from 'three'; let moveFlag = false; var point = new THREE.PointLight(0xffffff, 1, 100); // point.position.set(0, 0, 0); const sphereSize = 0.5;//辅助对象的大小 const pointLightHelper = new THREE.PointLightHelper(point, sphereSize, 0xFF00FF); // const axisHelper = new THREE.AxesHelper(5); export default function pointLight(vis) { let domContainer = document.getElementById('threeContainer'); if (vis) { window.controls.enableRotate = false; domContainer?.addEventListener('mousedown', onmousedown); domContainer?.addEventListener('mousemove', onmousemove); domContainer?.addEventListener('mouseup', onmouseup); window.controls.addEventListener("change", onPointerMove); // 增加点光源 window.threescene.add(point); // 需要捕获鼠标点击未松开时的位置作为点光源的位置 window.threescene.add(pointLightHelper); } else { // 卸载点光源 } } // 写个方法开始获取鼠标按下事件,然后将坐标位置转化为三维坐标 // 进入了这个页面就不再触发模型拖动事件了 function onmousedown(event) { moveFlag = true; console.log(event, 'mousedown事件'); } function onmousemove(event) { if (moveFlag) { console.log('mousemove事件'); const mouseX = event.clientX; const mouseY = event.clientY; const vector = new THREE.Vector3( (mouseX / window.innerWidth) * 2 - 1, -(mouseY / window.innerHeight) * 2 + 1, 0.5 ); vector.unproject(window.camera); const dir = vector.sub(window.camera.position).normalize(); const distance = -window.camera.position.z / dir.z; const pos = window.camera.position.clone().add(dir.multiplyScalar(distance)); console.log(pos,'pos'); point.position.copy(pos); console.log(point.position,'point'); pointLightHelper.light = point; } } function onmouseup() { moveFlag = false; console.log('mouseup事件'); } function onPointerMove() { // 如何取消调拖拽事件,而取消查看点光源后再打开 // 操作render函数吗 console.log('change事件'); }
最新发布
05-31

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值