function
mobileClick(
ele) {
if (
!
ele) {
return
false;
}
ele
.
addEventListener(
"
touchstart
",
function(
evt){
this
.
setAttribute(
"
data-moved
",
"
n
");
var
p
=
evt
.
touches[
0];
this
.
setAttribute(
"
data-touch-start-clientx
",
p
.
clientX);
this
.
setAttribute(
"
data-touch-start-clienty
",
p
.
clientY);
});
ele
.
addEventListener(
"
touchmove
",
function(
evt){
if (
this
.
getAttribute(
"
data-moved
")
==
"
y
")
return
false;
var
p
=
evt
.
touches[
0];
var
startClientX
=
parseInt(
this
.
getAttribute(
"
data-touch-start-clientx
"),
10);
var
startClientY
=
parseInt(
this
.
getAttribute(
"
data-touch-start-clienty
"),
10);
var
deltax
=
p
.
clientX
-
startClientX;
var
deltay
=
p
.
clientY
-
startClientY;
if (
Math
.
abs(
deltax)
>
10
||
Math
.
abs(
deltay)
>
10) {
this
.
setAttribute(
"
data-moved
",
"
y
");
}
});
ele
.
addEventListener(
"
touchend
",
function(
evt) {
if (
this
.
getAttribute(
"
data-moved
")
==
"
y
") {
evt
.
stopImmediatePropagation();
return
false;
}
});
}
//
防止滑动触发点击事件
function
getElementsClass(
classnames){
var
classobj
=
new
Array();
//
定义数组
var
classint
=
0;
//
定义数组的下标
var
tags
=
document
.
getElementsByTagName(
"
*
");
//
获取HTML的所有标签
for(
var
i
in
tags){
//
对标签进行遍历
if(
tags[
i]
.
nodeType
==
1){
//
判断节点类型
if(
tags[
i]
.
getAttribute(
"
class
")
==
classnames)
//
判断和需要CLASS名字相同的,并组成一个数组
{
classobj[
classint]
=
tags[
i];
classint
++;
}
}
}
return
classobj;
//
返回组成的数组
}
//
获取dom节点
function
getElementsClass(
classnames){
var
classobj
=
new
Array();
var
classint
=
0;
var
tags
=
document
.
getElementsByTagName(
"
*
");
for(
var
i
in
tags){
if(
tags[
i]
.
nodeType
==
1){
if(
tags[
i]
.
getAttribute(
"
class
")
==
classnames)
{
classobj[
classint]
=
tags[
i];
classint
++;
}
}
}
return
classobj;
}