touch事件

可封装的js代码

if (typeof YwkMobile == "undefined") var YwkMobile = {};
YwkMobile.touchStyle = function(e, t) {
$(e).bind("touchstart",
function() {
$(this).addClass(t)
}),
$(e).bind("touchmove",
function() {
$(this).removeClass(t)
}),
$(e).bind("touchend",
function() {
$(this).removeClass(t)
}),
$(e).bind("touchend",
function() {
$(this).removeClass(t)
}),
$(e).bind("touchcancel",
function() {
$(this).removeClass(t)
})
},
YwkMobile.gotoDetail = function(e, t) {
$(e).bind("click",
function() {
window.location.href = $(this).attr(t)
})
}
//

html中调用方法

//touch事件
$(function(){
YwkMobile.touchStyle('.navlist li a ,.product-list li','mtouchs');
});

css

添加类mtouchs可以写成touch事件触摸后的样式

.product-list li.mtouchs{}

是添加类mtouchs,所以中间不能有空格












原文地址:https://www.cnblogs.com/snowbaby-kang/p/3781670.html