1. CSS引入 slide-unlock.css
2. JS引入 jquery-1.10.2.js 和 jquery.slideunlock.js
<script>
$(function () {
var slider = new SliderUnlock("#slider",{
successLabelTip : "验证成功"
},function(){
alert("验证成功,即将跳转至百度");
window.location.href="http://www.baidu.com"
});
slider.init();
})
</script>
我自己调整了一下,把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();
}
});
};