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,所以中间不能有空格

 












posted @ 2014-06-11 12:11  雪宝贝_kang  阅读(229)  评论(0编辑  收藏  举报