android2.3的不支持滚动条,并且scrollTop也不支持的。(设置overflow未hidden就可以支持)。
function noBarsOnTouchScreen(arg)
{
var elem, tx, ty;
if(‘ontouchstart‘ in document.documentElement )
{
if (elem = document.getElementByIdx_x(arg)) {
elem.style.overflow = ‘hidden‘;
elem.ontouchstart = ts;
elem.ontouchmove = tm;
}
}
function ts( e )
{
var
tch;
if( e.touches.length == 1 )
{
e.stopPropagation();
tch = e.touches[ 0 ];
tx = tch.pageX;
ty = tch.pageY;
}
}
function tm( e )
{
var
tch;
if( e.touches.length == 1 )
{
e.preventDefault();
e.stopPropagation();
tch = e.touches[ 0 ];
this.scrollTop += ty - tch.pageY;
ty = tch.pageY;
}
}
}
调用的时候:noBarsOnTouchScreen(divId);
来源:http://www.myexception.cn/web/411975.html