之前的这篇博客"通过项目中定位的一个问题:学习ionic框架$ionicPopover的使用以及注意事项"介绍了popover组件的基本使用,可以参考这篇文章学习下popover组件的使用。最近项目发现了一个新问题:当popover下面放置很多按钮的时候,手机端上不能显示全部按钮,而且不能滑动。
我们项目使用的popover组件模板如下:
<script id="my-popover.html" type="text/ng-template">
<ion-popover-view>
<div class="list">
#foreach( $button in $comp.buttons )
$builder.render($button)
#end
</div>
</ion-popover-view>
</script>
我们可以用下面这段模拟模拟上面项目中的模板:
<script id="my-popover.html" type="text/ng-template">
<ion-popover-view >
<div class="list">
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
</div class="list">
</ion-popover-view>
</script>
可以看到:由于popover内容过多,页面根本显示不下,也没有滚动条。
解决方案1:使用<ion-content>
<script id="my-popover.html" type="text/ng-template">
<ion-popover-view >
<ion-content>
<div class="list">
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
</div class="list">
</ion-content>
</ion-popover-view>
</script>
可以看到:能够正常滚动,但是显示效果不好看,popover高度太小。我们可以给<ion-content>设定一个固定的高度,如<ion-content style="height:500px;">,显示效果图如下。
方案2:使用<ion-scroll>
<script id="my-popover.html" type="text/ng-template">
<ion-popover-view>
<ion-scroll direction="y" style="height:500px;">
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
<div style="background-color:green;height:100px"></div>
<div style="background-color:red;height:100px"></div>
</ion-scroll>
</ion-popover-view>
</script>