左右滑事件:
function changing(p,l,r) {
//p要调用函数的对象L、R回调函数
//这个函数深刻理解了函数的生命周期
var x1 , a , x2 ,s;
//手指按下
p.ontouchstart = function(event){
this.ontouchend=null
var ev = event.targetTouches[0];
x1 = ev.pageX;
};
//手指移动
p.ontouchmove = function(){
var ev = event.targetTouches[0];
x2 = x1 - ev.pageX;
//手指抬起
p.ontouchend = function(){
if(x2 >= 15){
//回调函数
s = l(p)
}else if(x2 < -15 ){
//回调函数
s = r(p)
}
}
};
}
滚轮使用:
var uls = document.getElementsByTagName("ul")[0];
var lis = uls.getElementsByTagName("li");
var hei = lis[0].clientHeight;
console.log(hei)
var num = 0;
function fun(e){
var sco = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
var e = e || window.event;
var dal = e.wheelDelta || e.datail;
//正是向上,负是向下
console.log(dal)
if ( dal < 0 ) {
if(num < lis.length){
num++;
$("div div").eq(num).addClass("no").siblings().removeClass("no");
document.body.scrollTop = num * hei;
}
} else{
if(num > 0){
num--;
$("div div").eq(num).addClass("no").siblings().removeClass("no");
document.body.scrollTop = num * hei;
}
}
}
window.onmousewheel = fun;