//?注释部分不是很理解
$(function(){
var size=$(window).width()/20;
$("html").css("font-size",size);
var myscroll=new IScroll("#file-list");
attachEvent($("#file-list li"),function(){
$(this).remove();
})
})
function attachEvent(src,cb){
$(src).unbind();//?
var isTouchDevice="ontouchstart"in window||navigator.msMaxTouchPoints;//?
if(isTouchDevice){
$(src).bind("touchstart",function(event){
$(this).data("touchon",true);//?
$(this).addClass("pressed");
});
$(src).bind("touchend",function(){
if($(this).data("touchon")){//?
cb.bind(this)();//?
}
$(this).data("touchon",false);
});
$(src).bind("touchmove",function(){
$(this).data("touchon",false);
$(this).removeClass("pressed");
})
}else{
//绑定鼠标事件
$(src).bind("mousedown",function(){
$(this).addClass("pressed");
$(this).data("touchon",true);
cb.bind(this)();
});
$(src).bind("mouseup",function(){
$(this).removeClass("pressed");
$(this).data("touchon",false);
cb.bind(this)();
})
}
}
$(src).unbind(); 就是取消绑定咯,然后后面再绑定。
var isTouchDevice="ontouchstart"in window||navigator.msMaxTouchPoints //判断是否是触屏.
"ontouchstart"in window:看window对象有没有ontouchstart属性,如果有window.ontouchstart,这个 "ontouchstart"in window会返回true. 后同。