位置: IT常识 - 正文

uniapp scroll-view基础用法

编辑:rootadmin
uniapp scroll-view基础用法 前言

推荐整理分享uniapp scroll-view基础用法,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

        在uniapp日常开发的过程中经常会有局部滚动的需求,而scroll-view组件正好可以满足这一需求。需注意在webview渲染的页面中,区域滚动的性能不及页面滚动。

纵向滚动

        将scroll-view组件中的属性scroll-y设定为true开启纵向滚动功能,给scroll-view设置一个高度,当内容高度大于scroll-view高度时即可开启滚动功能(内容高度小于scroll-view高度时无法体现滚动功能)

实现代码:

<template><view><scroll-view scroll-y="true" style="height: 700rpx;"><view v-for="(item,index) in 3" style="height: 500rpx;" :style="{ backgroundColor: colorList[index]}">{{index}}</view></scroll-view></view></template><script>export default {data() {return {colorList:["blue","red","yellow"]}},methods: {}}</script><style></style>

效果图:

横向滚动

        将scroll-view组件中的属性scroll-x设定为true开启横向滚动功能,给scroll-view设置一个宽度,当内容宽度大于scroll-view宽度时即可开启滚动功能(内容宽度小于scroll-view宽度时无法体现滚动功能)

        注意:scroll-view本身的display:flex不生效、如果想实现display:flex功能,则可以给scroll-view加上white-space: nowrap,给内容容器加上display:inline-block

实现代码:

<template><view><scroll-view scroll-x="true" style="height: 500rpx;white-space: nowrap;"><view v-for="(item,index) in 3" style="height: 500rpx;width: 100%;display: inline-block;" :style="{ backgroundColor: colorList[index]}">{{index}}</view></scroll-view></view></template><script>export default {data() {return {colorList:["blue","red","yellow"]}},methods: {}}</script><style></style>

效果图:

 锚点定位uniapp scroll-view基础用法

        当我们已进入页面就需要滚动到某一个元素的时候,锚点定位就可以很好的帮助我们定位并滚动到指定位置

        将scroll-with-animation设定为true开启动画效果、对scroll-into-view进行动态绑定

        注意:scroll-into-view绑定的值得是字符串,使用其他类型则会报错

实现代码:

<template><view><scroll-view scroll-x="true" style="height: 500rpx;white-space: nowrap;" scroll-with-animation="true" :scroll-into-view="'scroll'+scrollId"><view v-for="(item,index) in 3" style="height: 500rpx;width: 80%;display: inline-block;" :style="{ backgroundColor: colorList[index]}" :id="'scroll'+index">{{index}}</view></scroll-view></view></template><script>export default {data() {return {colorList:["blue","red","yellow"],scrollId:1}},methods: {}}</script><style></style>

效果图:

触底事件       

        在滑动的数据需要懒加载的时候,我们就需要通过用户滑动到底部时触发懒加载方法,通过绑定scrolltolower方法即可实现纵/横触底时触发懒加载方法

实现代码:

<template><view><scroll-view scroll-x="true" style="height: 500rpx;white-space: nowrap;" @scrolltolower="onReachScollBottom"><view v-for="(item,index) in 3" style="height: 500rpx;width: 80%;display: inline-block;" :style="{ backgroundColor: colorList[index]}">{{index}}</view></scroll-view></view></template><script>export default {data() {return {colorList:["blue","red","yellow"],}},methods: {onReachScollBottom(){uni.showToast({title:"触发了触底事件",duration:1500,icon:"none"})}}}</script><style></style>

 效果图:

 下拉刷新事件

        scroll-view组件也可以满足我们下拉刷新的需求、首先通过设置refresher-enabled为true开启下拉加载、动态绑定refresher-triggered对下拉加载的状态进行控制、绑定refresherrefresh触发下拉刷新事件

实现代码:

<template><view><scroll-view scroll-x="true" style="height: 500rpx;white-space: nowrap;" refresher-enabled="true" :refresher-triggered="refresh" @refresherrefresh="onRefresh"><view v-for="(item,index) in 3" style="height: 500rpx;width: 80%;display: inline-block;" :style="{ backgroundColor: colorList[index]}">{{index}}</view></scroll-view></view></template><script>export default {data() {return {colorList:["blue","red","yellow"],refresh: false}},methods: {onRefresh() {this.refresh= true;uni.showToast({title:"触发了下拉刷新",duration:1500,icon:"none"})// 这里不能直接让refresh直接为false,否则可能会发生下拉加载无法复位的情况setTimeout(() => {this.refresh = false;}, 500)}}}</script><style></style>

效果图:

 总结

        以上就是我整理的scroll-view的基础用法、想要了解更多的用法可以前往uniapp scroll-view部分进行了解

本文链接地址:https://www.jiuchutong.com/zhishi/299191.html 转载请保留说明!

上一篇:controller层,service层,mapper层,entity层的作用与联系。(controller层,service层,dao)

下一篇:和月薪5W的阿里程序员聊过后,才知道自己一直在打杂...(阿里月薪3万到手多少)

  • 工业企业应缴纳的税金有哪些
  • 分公司需要独立法人吗
  • 应付账款暂估款的会计分录
  • 企业保持存货的必要性是什么
  • 政府返还的个税怎么算
  • 计税依据的定义
  • 红字信息表撤销失败B80095
  • 代购货物的缴税情况
  • 现金流量表公式大全
  • 房地产企业城建税预缴可以抵扣吗
  • 收到的油费预付怎么入账
  • 给不是本单位的人开证明
  • 跨年度租金收入怎么算
  • 水电费没有票怎么做账
  • 其他应付款余额在借方表示什么意思
  • 收购发票盖章盖谁的
  • 金蝶年结后发现错误怎么办
  • 合伙企业分配比例税法规定
  • 预收账款长期挂账如何处理
  • 兼职人员个税起征点
  • 个税手续费返还要交增值税吗
  • 怎么给分区
  • php基于反射机制实验报告
  • 收到供应商现金回扣
  • 税款缴纳期初未缴税额
  • laravel 自定义类
  • 转出未交增值税借方余额表示什么
  • php smtp类
  • vue-nginx刷新404问题
  • 建筑业异地预缴增值税
  • split 文件分割
  • 增值税直接减征的情形
  • 社保基数填错了 多扣多钱可以退款吗
  • mongodb官方文档中文
  • 工程咨询服务发展的指导意见有哪些
  • 国际货运代理需要什么样的人才
  • 旅行社开具的发票抵扣
  • 出口后收不到货款
  • 未计提坏账准备发生坏账如何处理
  • 购进无偿赠送
  • 应付帐款不用付了的分录怎么处理
  • 专票金额和实际报销金额不符
  • 员工报销固定资产怎么算
  • 开办费账务处理实操案例
  • 付给第三方的差额是什么
  • 每个月计提工资没有发怎么办
  • 发票专用章盖在中间行不行
  • 收到专票可以不签字吗
  • 公司发放工资的形式
  • mysql数据库中储存的是
  • windows10显示
  • ubuntu 无线wifi
  • openbsd4.1+apache+mysql+php 环境配置
  • 2014年电脑装win7与win10
  • win8屏幕显示不全
  • ubuntu修改ip地址方法
  • linux获取主目录的命令
  • linux 更新系统
  • system idle process 连接了外网
  • win10 rs3
  • centos dvd安装
  • linux系统中make的用法
  • win10edge浏览器怎么设置兼容模式
  • 教程:如何在Win10 PC上玩Pokémon Go游戏
  • certutil - decode/encode BASE64/HEX strings.Print symbols by HEX code
  • 一键清除照片上多余的人
  • unity怎么打光
  • Javascript WebSocket使用实例介绍(简明入门教程)
  • nodejs客户端框架
  • css选择器 菜鸟教程
  • css渲染规则
  • javascript的dom
  • jquery设置div的宽度和高度
  • python调用ch
  • 税控盘忘记抄报罚多少
  • 变更主管税务机关需要注销吗
  • 河南电子发票申请流程
  • 土地增值税的房屋转让指出售 赠与
  • 《税收实务》
  • 电力营销岗
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设