我自己调整了一下,把SliderUnlock.prototype.init这个方法改了如下:
SliderUnlock.prototype.init = function() { var me = this; me.updateView(); var btn = $('#label')[0]; var btnWidth = btn.offsetWidth; btn.ondragstart = function() { alert("ondragstart"); return false; }; btn.onselectstart = function() { alert("onselectstart"); return false; }; //pc端 btn.onmousedown = function(e) { var disX = e.clientX - btn.offsetLeft; var e = e || window.event; me.lableIndex = e.clientX - btn.offsetLeft; me.handerIn(); document.onmousemove = function(event) { me.handerMove(event); }; document.onmouseup = function(event) { if (!me.isOk) { me.handerOut(); } }; document.mouseout = function(event) { me.handerOut(); }; }; //移动端 var cont = $("#label"); cont.on({ //绑定事件 touchstart: function(event) { var e = event || window.event; me.lableIndex = e.originalEvent.touches[0].pageX - this.offsetLeft; me.handerIn(); }, touchmove: function(event) { me.handerMove(event, "mobile"); }, touchend: function(event) { me.handerOut(); } }); };