ionic框架popover组件<ion-popover-view>的滚动问题

博客讨论了在ionic项目中,当popover内容过多导致无法显示全部并缺失滚动功能的问题。提出了两种解决方案:1) 使用<ion-content>,虽然能实现滚动但可能影响popover的显示效果;2) 使用<ion-scroll>来解决滚动问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

之前的这篇博客"通过项目中定位的一个问题:学习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>	



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值