H5_0028:自定义事件并调用

1,自定义事件并自己触发事件

   // 定义事件方法
function MyMousedown( event ) { if ( _this.enabled === false ) return; event.preventDefault(); event.stopPropagation(); if ( _state === STATE.NONE ) { _state = event.button; } if ( _state === STATE.ROTATE && !_this.noRotate ) { // _this.getMouseProjectionOnBall( event.pageX, event.pageY, _rotateStart ); _this.getMouseProjectionOnBall( event.pageX, event.pageY, _rotateStart ); _rotateEnd.copy(_rotateStart) } else if ( _state === STATE.ZOOM && !_this.noZoom ) { _this.getMouseOnScreen( event.pageX, event.pageY, _zoomStart ); _zoomEnd.copy(_zoomStart); } else if ( _state === STATE.PAN && !_this.noPan ) { _this.getMouseOnScreen( event.pageX, event.pageY, _panStart ); _panEnd.copy(_panStart) } window.addEventListener( 'MyMousemove', MyMousemove, false ); window.addEventListener( 'MyMouseup', MyMouseup, false ); _this.dispatchEvent( startEvent ); }

// 添加事件监听
    window.addEventListener( 'MyMousedown', MyMousedown, false );
 
  
    // 触发事件
    // window.dispatchEvent(new Event('MyMousedown'));




            // 自定义resize事件
            var myEvent = new Event('resize');
            window.dispatchEvent(myEvent);



 

posted @ 2020-03-04 19:43  琥珀君  阅读(366)  评论(0编辑  收藏  举报