我已按照Skrollr网站上的说明以及此问题(How to fix Skrollr on Mobile?)进行操作。我的问题是,当我将id =“scrollr-body”添加到我的body标签时,滚动停止在任何地方工作。
这是我在页脚中使用的代码:
<script type="text/javascript">
skrollrCheck = function() {
var winWidth = window.innerWidth;
var winHeight = window.innerHeight;
if(winWidth >= 768) {
if(document.body.id !== 'skrollr-body') {
document.body.id = 'skrollr-body';
// Init Skrollr
skrollr.init({
forceHeight: false,//disable setting height on body
mobileDeceleration:0.04,
smoothScrolling:true,
render: function(data) {
//Debugging - Log the current scroll position.
//console.log('data.curTop: ' + data.curTop);
}
});
}
if(winWidth > winHeight) {
console.log('orientation is landscape');
skrollr.get().refresh();
} else if (winWidth < winHeight) {
console.log('orientation is portrait');
skrollr.get().refresh();
}
} else if (winWidth < 768){
// Destroy skrollr for screens less than 600px
if(document.body.id === 'skrollr-body') {
skrollr.init().destroy();
document.body.id = '';
}
}
};
//Initialize skrollr, but only if it exists.
if(typeof skrollr !== typeof undefined){
// INITIALIZE
window.onload = skrollrCheck();
window.addEventListener('resize', skrollrCheck);//listens for resize,
and refreshes skrollr
window.addEventListener('orientationchange', skrollrCheck);//listens
for
orientation change, and refreshes skrollr
console.log('skrollr active!');
} else {
console.log('skrollr is did not load.');
}
</script>
如果我从body标签中删除了scrollr-body id,则视差滚动在桌面上运行良好,但滚动在iPad上根本不起作用。如果我添加它,视差从任何地方消失,但iPad工作正常。有任何想法吗?谢谢!
答案 0 :(得分:1)
好吧,我在页脚中使用了更简单的代码版本:
<script type="text/javascript" src="js/skrollr.js"></script>
<script type="text/javascript">
skrollr.init({
smoothScrolling: false
});
而不是动态地将skrollr-body插入到标签中,我只是将所有页面内容包装在:
<div id="skrollr-body">
<强>更新强>
这仍然没有使用最新的iPad3滚动,所以我现在使用以下内容:
<script type="text/javascript">
if(!(/Android|iPhone|iPad|iPod|BlackBerry|Windows Phone/i).test(navigator.userAgent || navigator.vendor || window.opera)){
skrollr.init({
forceHeight: false
});
}
</script>