我正在尝试使用jQuery / JavaScript设置滚动。我无法弄清楚如何使用iOS和平板电脑的视口。任何帮助将不胜感激。我需要使用$ .Scroll进行设计/动画。
谢谢,
这是我到目前为止所拥有的:
var isIphone = navigator.userAgent.match(/iPhone/i) != null;
var isIpod = navigator.userAgent.match(/iPod/i) != null;
var isIpad = navigator.userAgent.match(/iPad/i) != null;
// now set one variable for all iOS devices
// What do I do for Tablet PC's?
var isIos = isIphone || isIpod || isIpad;
jQuery(function ($) {
$.Window = $(window); // We'll use this later on
$.Body = $('body');
if ( !isIos ) {
// Ternary for desktop
$.Scroll = ($.browser.mozilla || $.browser.msie) ? $('html') : $.Body;
} else {
// Need to detect iOS and Tablet PC's
$.Scroll = $.Body;
}
});
更新:
谢谢,到目前为止的输入!
我已经弄明白了如何访问iOS touch事件:
$.Window
.bind('touchmove',
function (e) {
//code goes here
})
.bind('scroll',
function (e) {
//code goes here
})
这似乎适用于滚动和触摸事件。
答案 0 :(得分:0)
我认为window.scrollTo(x,y)会得到你想要的,但你需要确保窗口实际上是可滚动的(即内容大于窗口,并且可以滚动主体溢出)。
Sidenote :我没有看到有人在 jQuery库中存储变量。为什么不做var scrollableObject = ($.browser.mozilla || $.browser.msie) ? $('html') : $.Body;
?
答案 1 :(得分:0)
iOS会在滚动时停止计时器,因此大多数情况下基于计时器的动画无法正常工作。我的滚动很好,只是jQuery .animate与iOS Safari的滚动类型的实现不兼容。