欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

IOS上iframe的滾動條失效的解決辦法

 更新時間:2021年03月19日 15:46:10   作者:荒漠千蝶  
這篇文章主要為大家詳細介紹了IOS上iframe的滾動條失效的解決辦法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

問題描述: 

iframe設置了高度(例如500px)。倘若iframe的內(nèi)容足夠長超出了iframe設定的高度時,在ipad等設備上。iframe內(nèi)部html的滾動條不出現(xiàn)。并且活生生的從500px處截斷,(類似overflow:hidden的效果)下面的內(nèi)容不再顯示。 

問題重現(xiàn):

結構:

index.html :

<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">
 我是一堆很長。很長,很高,很高的內(nèi)容。
</div>
<script src="../jquery.js"></script>
</body>
</html>

 問題原因:

在IOS設備中,iframe內(nèi)部的html的滾動條無法生效。

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

 解決辦法:

把iframe中body里的內(nèi)容全部包裹一層,然后設置包裹這一層的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">
 我是一堆很長。很長,很高,很高的內(nèi)容。
</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>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論