https://www.w3cmm.com/javascript/touch.html //触摸与手势事件连接
tinyscrollbar
//方法1
var _this = $('#fabu');
var scrollFunc=function(e){
e=e||window.event;
if(e.wheelDelta){//IE/Opera/Chrome
if(e.wheelDelta==-120){
_this.hide();
}else{
_this.show();
}
}else if(e.detail){
//Firefox
if(e.detail==-3){
_this.hide();
}else{
_this.show();
}
}
};
if(document.addEventListener){//注册事件
document.addEventListener("onmousewheel" ,scrollFunc, false);
}
//IE/Opera/Chrome
window.onmousewheel=document.onmousewheel=scrollFunc;
//方法----------稍微有点动画
//发布按钮上滑消失,下滑出现
var startY, endY;
document.addEventListener('touchstart', function (e) {
startY = e.touches[0].pageY;
console.log(startY)
}, false);
document.addEventListener('touchmove', function (e) {
endY = e.changedTouches[0].pageY;
moveLoad();
}, false);
function moveLoad() {
var movY = endY - startY;
var fabu = document.getElementById('fabu');
if (movY > 0) {
jQuery("#fabu").animate({bottom:"10px"},0.1).fadeIn(50);
}
else {
jQuery("#fabu").animate({bottom:"-60px"},0.5).fadeOut(50);
}
}
//方法2
function getData(event) {
var e = event || window.event;
//获取滚动距离(FF每次滚动 data为3或者-3,其他为120或者-120 等于3是向上滚动,等于-3是向下滚动)
var data = e.detail || e.wheelDelta;
if(data==3){
_this.hide();
}else if(data==-3){
_this.show();
}
}
//IE之外的绑定事件方法
if (document.addEventListener && !document.attachEvent) {
document.addEventListener('mousewheel', getData);
//FF绑定滚动事件
document.addEventListener('DOMMouseScroll', getData);
}
//IE
else if (document.attachEvent && !document.addEventListener) {
document.attachEvent('onmousewheel', getData);
} else {
window.onmousewheel = getData;
}
//http://www.tuicool.com/articles/vANraay
//方法3 手机端滑动监听事件
//发布按钮上滑消失,下滑出现
//var _this = $('#fabu');
var startY,endY;
document.addEventListener('touchstart',function(e){
startY= e.touches[0].pageY;
},false);
document.addEventListener('touchend',function(e){
endY= e.changedTouches[0].pageY;
moveLoad();
},false);
function moveLoad(){
var movY=endY-startY;
if(movY<-80){
//_this.hide();
alert(123)
}else{
//_this.show();
}
}