当前位置: 移动技术网 > IT编程>移动开发>IOS > IOS上iframe的滚动条失效的解决办法

IOS上iframe的滚动条失效的解决办法

2019年07月24日  | 移动技术网IT编程  | 我要评论

王华滔,长歌惊弦录,人类未解之谜

问题描述: 

iframe设置了高度(例如500px)。倘若iframe的内容足够长超出了iframe设定的高度时,在ipad等设备上。iframe内部html的滚动条不出现。并且活生生的从500px处截断,(类似overflow:hidden的效果)下面的内容不再显示。 

问题重现:

结构: 

:

<style>  

#iframe{height:500px;}

</style>

<div id="content">
  <iframe frameborder="0" src="iframe.html" id="iframe"></iframe>
</div> 

iframe.html: 

<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<title>ios frame 滚动条 demo</title>
</head>
<body><div class="container">
  我是一堆很长。很长,很高,很高的内容。
</div>
<script src="../jquery.js"></script>
</body>
</html>

 问题原因: 

在ios设备中,iframe内部的html的滚动条无法生效。 

--------------------------------------------------------------------------------

 解决办法: 

把iframe中body里的内容全部包裹一层,然后设置包裹这一层的height,使用属性-webkit-overflow-scrolling:touch;overflow:auto; 

代码如下: 

iframe.html

<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="utf-8" />
<title>ios frame 滚动条 demo</title>
</head>
<body>
<style>
#wrapper{height:500px;-webkit-overflow-scrolling:touch;overflow:auto;}
</style>
<div class="container">
  我是一堆很长。很长,很高,很高的内容。
</div>
<script src="../jquery.js"></script>
<script>
  var ua = navigator.useragent;
  var forios = function(){
    if(!ua.match(/ipad/) && !ua.match(/iphone/) && !ua.match(/ipod/)){return;}
    if($('#wrapper').length){return;}
    $('body').children().not('script').wrapall('<div id="wrapper"></div>');
  }();
</script>
</body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网