在 iFrame 中滚动事件侦听器在 iOS 上不起作用
Scroll event listener not working on iOS in iFrame
我需要认真的帮助。我已经使用滚动事件侦听器对一个网站进行了编程,以根据用户滚动的深度对某些图形进行动画处理。
在桌面和iOS上运行良好。唯一的问题是这个站点需要嵌入到iFrame中。仍然可以在桌面上使用,但在 iOS 中不起作用。
我设置了一个示例来说明我的意思。
首先在桌面上查看此页面,然后在iOS上查看此页面。http://www.webzeile.com/iframescroll/index.html
固定元素(滚动仪表)在iOS中不固定,我没有机会在这里获得scrollTop。
主页(我没有机会在这里修改 iframe 属性)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>index</title>
<style type="text/css" media="screen">
html, body {
overflow-y:auto;
}
</style>
</head>
<body>
<div style="-webkit-overflow-scrolling: touch !important; overflow:auto; width:800px; height:500px; margin:0px auto;">
<iframe id="iframe" scrolling="auto" webkitallowfullscreen frameborder="0" style="width:100%; height:100%;" src="iframe.html"></iframe>
</div>
内嵌框架内容
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>index</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<style type="text/css" media="screen">
html, body {
overflow-y:auto;
margin:0px;
padding:0px;
}
.div1, .div2 {
margin:0px;
padding:0px;
height:700px;
margin:0px;
position:relative;
width:100%;
}
.div1 {
background:green;
}
.div2 {
background:orange;
top:100%;
}
#scrollindicator {
color:#fff;
position:fixed;
right:20px;
top:20px;
z-index:1000;
width:150px;
height:25px;
}
</style>
</head>
<body>
<div class="div1">
<h1>Content 1</h1>
</div>
<div class="div2">
<h1>Content 2</h1>
<a href="#" onclick="alert($(window).scrollTop()); return false;">Alert scroll top</a>
<a href="#" onclick="alert(window.pageYOffset); return false;">Alert Y offset</a>
</div>
<div id="scrollindicator">
Scroll o meter: 0
</div>
<script type="text/javascript">
$(window).scroll(function () {
$("#scrollindicator").html("Scroll o meter: "+$(window).scrollTop());
});
</script>
</body>
</html>
尝试了一切。无法让滚动处理程序在 iOS 上运行。有什么想法吗?
我看到你最终放弃了 IFrames,但我今天在遇到类似问题时发现了这个问题。 我试图检测用户何时从 IFrame 内部滚动到页面底部,而不是主页。 这是我提出的解决方案:
var totalY = 0;
function scroll_handler(e){
var t = $(window).scrollTop();
var h = $(window).height();
var el = $('#bottomdiv'); //This is an element at the bottom of the page
var bot = el.offset().top + (el.height()) - 400; //I wanted a 400px buffer
if (e.type == "touchend") {
totalY += e.originalEvent.changedTouches[0].clientY;
if ( !t ) {
t = totalY;
}
}
if ((t + h) >= bot) {
//Do Stuff when they get to the bottom of the page
}
}
if ( 'ontouchstart' in window ) {
$("body").on("touchend",scroll_handler);
} else {
$(window).scroll(scroll_handler);
}
它并不完美,但它有效 - 当用户向下滑动页面并将其添加到 totalY 时,它会获取触摸事件的 Y 位置。 如果该人滑动非常快并且在到达底部时根本不触摸屏幕,则失败。 但是,它适用于我的情况。
我希望这可以帮助其他人研究类似的问题。
相关文章:
- jQuery ContextMenu事件在IOS 8.2中不起作用
- Javascript touchend(滚动)事件在ios 4中的UIWebView中不起作用
- Ajax 调用在 IOS 中的用户交互之前不起作用
- window.open()在使用phone gap的iOS应用程序上不起作用
- Skrollr在IOS中不起作用,尽管i'We用Skrollr body包裹身体
- 删除类在 iOS 上不起作用
- Cordova iframe在iOS Safari中工作,但在Android中不起作用
- IOS Cordova/Phonegap 离线视频源标签不起作用
- <表单目标=“_blank”>在 iOS 7.0.3 中不起作用
- Jquery 函数在 ios 设备上不起作用
- 在 iFrame 中滚动事件侦听器在 iOS 上不起作用
- Vimeo 播放器 JS API 在 iOS 中不起作用
- 清除键盘打开时在iOS / iPad中不起作用的所有文本图标
- HTML
- 基于宽度计算的表格列显示和隐藏在 Safari IOS 设备中不起作用
- stringByEvaluatingJavaScriptFromString 在 iOS 7 中不起作用
- Ios webview调用javascript函数将不起作用
- 使用 ATTR 在 iOS 5 上不起作用更改 IMG 源
- Cordova iOS Javascript不起作用
- window.scroll到在iOS chrome中不起作用