微信小程序scroll-view组件官方文档  传送门

  提前准备:使用<view>组件制作五条撑满的横向区域

<!--index.wxml-->
Cynical丶Gary
<view > <!-- 手指按下后1s样式由a改变为d,手指松开后2s样式由d改变回a -->
<view class='a size'>a</view>
<view class='b size'>b</view>
<view class='c size'>c</view>
<view class='d size'>d</view>
<view class='e size'>e</view>
</view>

index.wxml

.container{
display: flex; } .size{
width: 100%;
height: 150rpx;
} .a{
background: red;
order:;
flex:;
} .b{
background: yellow;
order:;
flex:;
} .c{
background: blue;
order:;
flex:;
} .d{
background: green;
order:;
flex:;
} .e{
background: orange;
order:;
flex:;
}

index.wxss

 

  Learn

    一、scroll-y属性

    二、scroll-x属性

    

一、scroll-y属性

  scroll-y:允许纵向滚动【默认值false】

  使用<scroll-view>组件可以设置小程序中<view>组件纵向滚动,使用<scroll-view>组件时注意必须设置高度的样式如:style='height:300rpx'

<!--index.wxml-->
Cynical丶Gary
<scroll-view scroll-y="true" style='height:300rpx'> <!-- 手指按下后1s样式由a改变为d,手指松开后2s样式由d改变回a -->
<view class='a size'>a</view>
<view class='b size'>b</view>
<view class='c size'>c</view>
<view class='d size'>d</view>
<view class='e size'>e</view> </scroll-view>

index.wxml

.container{
display: flex; } .size{
width: 100%;
height: 150rpx;
} .a{
background: red;
order:;
flex:;
} .b{
background: yellow;
order:;
flex:;
} .c{
background: blue;
order:;
flex:;
} .d{
background: green;
order:;
flex:;
} .e{
background: orange;
order:;
flex:;
}

index.wxss

  upper-threshold:距顶部/左边多远时(单位px,2.4.0起支持rpx),触发 scrolltoupper 事件【默认值50】

  lower-threshold:距底部/右边多远时(单位px,2.4.0起支持rpx),触发 scrolltolower 事件【默认值50】

  bindscrolltoupper:滚动到顶部/左边,会触发 scrolltoupper 事件

  bindscrolltolower:滚动到底部/右边,会触发 scrolltolower 事件

  给<scroller-view>组件添加滚动触发事件

<scroll-view scroll-y="true" style='height:300rpx;'  bindscrolltoupper="scrolltoupper" bindscrolltolower="scrolltolower" >

  并在index.js中添加scrolltoupper函数事件和scrolltolower函数事件

  scrolltoupper:function(){
console.log("滚动到顶部");
},
scrolltolower:function(){
console.log("滚动到底部");
}

<!--index.wxml-->
Cynical丶Gary
<scroll-view scroll-y="true" style='height:300rpx;'
bindscrolltoupper="scrolltoupper" bindscrolltolower="scrolltolower" > <!-- 手指按下后1s样式由a改变为d,手指松开后2s样式由d改变回a -->
<view class='a size'>a</view>
<view class='b size'>b</view>
<view class='c size'>c</view>
<view class='d size'>d</view>
<view class='e size'>e</view> </scroll-view>

index.wxml

.container{
display: flex; } .size{
width: 100%;
height: 150rpx;
} .a{
background: red;
order:;
flex:;
} .b{
background: yellow;
order:;
flex:;
} .c{
background: blue;
order:;
flex:;
} .d{
background: green;
order:;
flex:;
} .e{
background: orange;
order:;
flex:;
}

index.wxss

Page({
data:{ }, scrolltoupper:function(){
console.log("滚动到顶部");
},
scrolltolower:function(){
console.log("滚动到底部");
} })

index.js

  当然我们也可以给<scroll-view>添加两个额外的属性upper-thresholdlower-threshold

  upper-threshold:距顶部/左边多远时(单位px,2.4.0起支持rpx),触发 scrolltoupper 事件【默认值50】

  lower-threshold:距底部/右边多远时(单位px,2.4.0起支持rpx),触发 scrolltolower 事件【默认值50】

  使用方法

<scroll-view scroll-y="true" style='height:300rpx;'
bindscrolltoupper="scrolltoupper" bindscrolltolower="scrolltolower" upper-threshold="0" lower-threshold="0">

  scroll-top:设置竖向滚动条位置(单位px,2.4.0起支持rpx)【无默认值】

  可以看到,当我们设置scroll-top="100"时,滚动条默认出现在距离顶部100px位置的地方,当我们设置scroll-top="150"时,滚动条默认出现在距离顶部150px位置的地方

<!--index.wxml-->
Cynical丶Gary
<scroll-view scroll-y="true" style='height:300rpx;'
bindscrolltoupper="scrolltoupper" bindscrolltolower="scrolltolower"
upper-threshold="0"
lower-threshold="0"
scroll-top="150"> <!-- 手指按下后1s样式由a改变为d,手指松开后2s样式由d改变回a -->
<view class='a size'>a</view>
<view class='b size'>b</view>
<view class='c size'>c</view>
<view class='d size'>d</view>
<view class='e size'>e</view> </scroll-view>

index.wxml

.container{
display: flex; } .size{
width: 100%;
height: 150rpx;
} .a{
background: red;
order:1;
flex:10;
} .b{
background: yellow;
order:2;
flex:2;
} .c{
background: blue;
order:3;
flex:1;
} .d{
background: green;
order:4;
flex:1;
} .e{
background: orange;
order:5;
flex:1;
}

index.wxss

Page({
data:{ }, scrolltoupper:function(){
console.log("滚动到顶部");
},
scrolltolower:function(){
console.log("滚动到底部");
} })

index.js

  enable-back-to-top:iOS点击顶部状态栏、安卓双击标题栏时,滚动条返回顶部,只支持竖向【默认值false】

  注意:微信小程序开发工具中默认在web环境中进行开发,而此属性需要在手机上运行~

  bindscroll:滚动时触发,event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}

  在index.js中添加滚动时触发的函数bindscroll()

  bindscroll:function(){
console.log("滚动中~");
}

  在index.wxml中进行事件绑定bindscroll="bindscroll"

  <scroll-view scroll-y="true" style='height:300rpx;'
  bindscrolltoupper="scrolltoupper" bindscrolltolower="scrolltolower"
  upper-threshold="0"
  lower-threshold="0"
  scroll-top="150"
  enable-back-to-top="true"
  bindscroll="bindscroll">

<!--index.wxml-->
Cynical丶Gary
<scroll-view scroll-y="true" style='height:300rpx;'
bindscrolltoupper="scrolltoupper" bindscrolltolower="scrolltolower"
upper-threshold="0"
lower-threshold="0"
scroll-top="150"
enable-back-to-top="true"
bindscroll="bindscroll"> <!-- 手指按下后1s样式由a改变为d,手指松开后2s样式由d改变回a -->
<view class='a size'>a</view>
<view class='b size'>b</view>
<view class='c size'>c</view>
<view class='d size'>d</view>
<view class='e size'>e</view> </scroll-view>

index.wxml

Page({
data:{ }, scrolltoupper:function(){
console.log("滚动到顶部");
},
scrolltolower:function(){
console.log("滚动到底部");
},
bindscroll:function(){
console.log("滚动中~");
} })

index.js

  

  scroll-into-view:值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素

  index.wxml中给五个<view>组件添加id元素

  <view id="a" class='a size'>a</view>
<view id="b" class='b size'>b</view>
<view id="c" class='c size'>c</view>
<view id="d" class='d size'>d</view>
<view id="e" class='e size'>e</view>

  通过scroll-into-view给<scroll-view>组件添加属性

  <scroll-view scroll-y="true" style='height:300rpx;'
  bindscrolltoupper="scrolltoupper" bindscrolltolower="scrolltolower"
  upper-threshold="0"
  lower-threshold="0"
  scroll-into-view="e"
  enable-back-to-top="true"
  bindscroll="bindscroll">

<!--index.wxml-->
Cynical丶Gary
<!-- scroll-top="150" -->
<scroll-view scroll-y="true" style='height:300rpx;'
bindscrolltoupper="scrolltoupper" bindscrolltolower="scrolltolower"
upper-threshold="0"
lower-threshold="0"
scroll-into-view="e"
enable-back-to-top="true"
bindscroll="bindscroll"> <!-- 手指按下后1s样式由a改变为d,手指松开后2s样式由d改变回a -->
<view id="a" class='a size'>a</view>
<view id="b" class='b size'>b</view>
<view id="c" class='c size'>c</view>
<view id="d" class='d size'>d</view>
<view id="e" class='e size'>e</view> </scroll-view>

index.wxml

Page({
data:{ }, scrolltoupper:function(){
console.log("滚动到顶部");
},
scrolltolower:function(){
console.log("滚动到底部");
},
bindscroll:function(){
console.log("滚动中~");
} })

index.js

二、scroll-x属性

  scroll-x:允许横向滚动【默认值为false】

  scroll-left:设置横向滚动条位置(单位px,2.4.0起支持rpx)

<!--index.wxml-->
Cynical丶Gary
<scroll-view class='container' scroll-x="true" style='height:300rpx;'
scroll-left="200">
<!-- 手指按下后1s样式由a改变为d,手指松开后2s样式由d改变回a -->
<view id="a" class='a size'>a</view>
<view id="b" class='b size'>b</view>
<view id="c" class='c size'>c</view>
<view id="d" class='d size'>d</view>
<view id="e" class='e size'>e</view>
</scroll-view>

index.wxml

.container{
display: flex;
white-space: nowrap;
} .size{
width: 250rpx;
height: 150rpx;
display:inline-block;
} .a{
background: red;
order:;
flex:;
} .b{
background: yellow;
order:;
flex:;
} .c{
background: blue;
order:;
flex:;
} .d{
background: green;
order:;
flex:;
} .e{
background: orange;
order:;
flex:;
}

index.wxss

Page({
data:{ }, scrolltoupper:function(){
console.log("滚动到顶部");
},
scrolltolower:function(){
console.log("滚动到底部");
},
bindscroll:function(){
console.log("滚动中~");
} })

index.js

微信小程序_(组件)scroll-view可滚动视图的更多相关文章

  1. 微信小程序_(组件)icon、text、rich-text、progress四大基础组件

    微信小程序基础组件官方文档 传送门 Learn 一.icon图标组件 二.rich-text富文本组件 三.text文本组件 四.progress进度条组件 一.icon图标组件 type:icon的 ...

  2. 微信小程序_(组件)可拖动movable-view

    微信小程序movable-view组件官方文档 传送门 Learn 一.moveable-view组件 一.movable-view组件 direction:movable-view的移动方向,属性值 ...

  3. 微信小程序_(组件)view视图容器

    微信小程序view组件官方文档 传送门 Learn 一.hover-class属性 二.hover-start-time与hover-stay-time属性 三.hover-stop-propagat ...

  4. 微信小程序_(组件)picker

    picker组件效果 官方文档:传送门 Page({ data: { array: ['美国', '中国', '巴西', '日本'], objectArray: [ { id: 0, name: '美 ...

  5. 微信小程序_(组件)组件基础

    (progress.text.block) 组件基础效果 官方文档:传送门 Page({ /** * 页面的初始数据 */ data: { text:"Gary 微信小程序\n", ...

  6. 微信小程序_(组件)canvas画布

    canvas画布效果 官方文档:传送门 Page({ canvasIdErrorCallback: function (e) { console.error(e.detail.errMsg) }, o ...

  7. 微信小程序_(组件)swiper轮播图

    微信小程序swiper轮播图组件官方文档 传送门 Learn: swiper组件 一.swiper组件 indicator-dots:是否显示面板指示点[默认值false] autoplay:是否自动 ...

  8. 微信小程序_(组件)flex布局

    小程序建议使用flex布局进行排版 flex是一个盒装弹性布局 flex是一个容器,所有子元素都是他的成员 定义布局:display:flex flex容器的属性: 一.flex-direction: ...

  9. 微信小程序_(组件)form表单

    Form表单.switch开关.数值选择器效果 官方文档:传送门 点击提交表单(按钮,提交开关,数值选择器,输入文本中)的值,显示在控制台上,点击重置,重置表单中的值. 实现过程 form表单,添加f ...

随机推荐

  1. 4-Perl 数据类型

    1.Perl 数据类型Perl 是一种弱类型语言,所以变量不需要指定类型,Perl 解释器会根据上下文自动选择匹配类型.Perl 有三个基本的数据类型:标量.数组.哈希.以下是这三种数据类型的说明:1 ...

  2. 执行sql语句,不依靠实体 获取string值

     IList<string> list2 = Session.CreateSQLQuery(sql.ToString()).List<string>();

  3. JavaSE基础知识之多态

    一. 概述 多态是继封装.继承之后,面向对象的第三大特性,指同一行为,具有多个不同表现形式.生活中,比如跑的动作,小猫.小狗和大象,跑起来是不一样的.再比如飞的动作,昆虫.鸟类和飞机,飞起来也是不一样 ...

  4. vue全局设置请求头 (封装axios请求)

    Vue.http.interceptors.push((request, next) => { // 请求发送前的处理逻辑 request.headers.set('Authorization' ...

  5. C# 使用Quartz.Net

    //首先在Nuget上下载 Quartz包 但是由于我睿智Nuget 怎么也没法用 于是找到了这个 解决方法: 1.点击右侧的设置按钮, 2.弹出窗中左侧树形结构选择“程序包源”,再点击右上方的添加按 ...

  6. 密码基础知识(2)以RSA为例说明加密、解密、签名、验签

    密码基础知识(1)https://www.cnblogs.com/xdyixia/p/11528572.html 一.RSA加密简介 RSA加密是一种非对称加密.是由一对密钥来进行加解密的过程,分别称 ...

  7. fastadmin中上传配置

    配置文件位于下图,默认代码如下 <?php //上传配置 return [ /** * 上传地址,默认是本地上传 */ 'rootpath' => '/uploads/', 'upload ...

  8. MySQL连表查询练习题

    1.建库 库名:linux50 字符集:utf8 校验规则:utf8_general_ci  create database linux4 charset utf8 default collate ...

  9. 针对西门子PLC蠕虫的实现 

    研究背景 随着“互联网+”.“中国智能制造2025“.“工业4.0”等概念的提出,为了提高生产率,独立.隔离的传统工控领域将迎来了新的互联网时代,越来越多的工控设备(如控制器.机器人.数控机床)将被暴 ...

  10. 09-【el表达式和jstl标签库】

    el表达式和jstl标签库 一:el表达式:表达式语言,jsp页面获取数据比较简单1.el表达式的语法(掌握)el表达式通常取值是获取作用域对象中的属性值:${属性名}=>是el表达式的简写的形 ...