onClick:function(options){
let tableid = options.tableid
,tableBox = $('[lay-id='+tableid+']')
,box = tableBox.find('.layui-table-main')
,elem = tableBox.find('.layui-table')
elem.on('contextmenu',function(e){
//屏幕右键菜单
e.preventDefault()
})
.on('mousedown',function(e){
if(e.which === 3){
// 右键
//dosomething
}
else if(e.which ===1){
// console.log('aasdfad')
// 左键
//dosomething
}
})
.on('DOMMouseScroll',function(e){
let tableScrollX = box.scrollLeft()
,delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1)) || // chrome & ie
(e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1)); // firefox
if (delta > 0) {
// 向上滚
box.scrollLeft(tableScrollX-100);
//do somthing
} else if (delta < 0) {
// 向下滚
box.scrollLeft(tableScrollX+100);
//do somthing
}
})
},
代码所各种点击情况都写进去了,鼠标左右键及滚轮滚动都写进去了,这里只用了滚轮的滚动。
调用
onClick({tableid:'tableid'})
|