可封装的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,所以中间不能有空格
本文介绍了一种使用封装的JS代码实现页面元素触摸事件触发动态样式切换的方法,包括如何在HTML中调用封装函数以及CSS样式应用规则。
4323

被折叠的 条评论
为什么被折叠?



