backbone.js 如何为平板电脑和台式机编写不同的事件

mspsb9vt  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(158)

根据我的规格,我必须在桌面和平板电脑中显示right click menu

我在桌面和平板电脑上使用相同的文件,所以我在Marionette.js中编写了以下内容
密码:

events:{
 //desktop events
 "contextmenu td":"checkingDeviceType",
 "contextmenu input":"checkingDeviceType",
 //tablet events
 "mousedown.LongTouch td":"checkingDeviceType",
 "mousedown.LongTouch input":"checkingDeviceType",
},
checkingDeviceType:function(event){
    var windowWidth=window.screen.width,self=this;
    if (windowWidth>1024) {
        //desktop view
        this.renderingfRightClickFeature(event);
    }else{
        //tablet view
        setTimeout(function(){
                self.renderingfRightClickFeature(event)},
                1000
        );
    };
},
renderingfRightClickFeature:function(event){
     //logic is here
     console.log("Right click menu code comes here");
   }

根据规范,在desktop中,如果用户按下右键,则会出现menu。在tablet中,同样的方式,在long press事件中,会出现右键菜单。
我所面临的问题:
即使我在桌面上单击(左键单击),right click menu也会出现。这意味着mousedown.LongTouch事件触发。但它不应该在桌面上触发。
我希望你能理解我的问题。谁能帮帮我?

lh80um4z

lh80um4z1#

我找到了解决方案,我用taphold事件代替了mousedown.LongTouch。现在它工作得很好。

相关问题