zoukankan      html  css  js  c++  java
  • uniapp中scroll-view滚动条的使用

    1、横向滚动基本写法

    <template>
        <view>
            <!-- 横向滚动条 -->
            <view class="uni-padding-wrap uni-common-mt">
                <scroll-view class="scroll-view_H" scroll-x="true" @scroll="scroll" scroll-left="100%" @scrolltolower="scrolltolower">
                    <view class="scroll-view-item_H uni-bg-red">A</view>
                    <view class="scroll-view-item_H uni-bg-green">B</view>
                    <view class="scroll-view-item_H uni-bg-blue">C</view>
                </scroll-view>
            </view>
        </view>
    </template>
    
    <script>
        export default {
            data() {
                return {
    
                }
            },
            methods: {
                scroll(event) {
                    //距离每个边界距离
                    console.log(event.detail)
                },
                //滚动到底部/右边触发
                scrolltolower() {
                    console.log(1111);
                },
                // 滚动到顶部/左边触发
                scrolltoupper() {
                    console.log(2222);
                }
            }
        }
    </script>
    
    <style lang="scss">
        .scroll-view_H {
            white-space: nowrap;
            .scroll-view-item_H {
                display: inline-block;
                 100%;
                height: 100px;
            }
            .uni-bg-red {
                background: red;
            }
            
            .uni-bg-green {
                background: green;
            }
            
            .uni-bg-blue {
                background: blue;
            }    
        }
    </style>

    2、纵向滚动基本写法

    <template>
        <view>
            <!-- 这层标签没有也可以 -->
            <view class="uni-padding-wrap uni-common-mt">
                <view>
                    <scroll-view class="scroll-view" scroll-y="true" :scroll-top="scrollTop" @scroll="scroll" @scrolltoupper="upper"
                     @scrolltolower="lower">
                        <view class="scroll-view-item top">上</view>
                        <view class="scroll-view-item center">中</view>
                        <view class="scroll-view-item bottom">下</view>
                    </scroll-view>
                </view>
                <view @tap="goTop" class="uni-link uni-center uni-common-mt">
                    点击这里返回顶部
                </view>
            </view>
        </view>
    </template>
    
    <script>
        export default {
            data() {
                return {
                    scrollTop: 0,
                    old: {
                        scrollTop: 0,
                    }
                }
            },
            methods: {
                scroll(e) {
                    this.old.scrollTop = e.detail.scrollTop
                },
                goTop() {
                    //这里必须将this.old.scrollTop值赋值给this.scrollTop
                    this.scrollTop = this.old.scrollTop;
                    this.$nextTick(function() {
                        this.scrollTop = 0
                    });
                },
                upper(){
                    // 滚动到顶部/左边触发
                },
                lower(){
                    // 滚动到底部/右边触发
                }
            }
    
        }
    </script>
    
    <style lang="scss">
        .scroll-view {
            // white-space: nowrap;
            height: 200px;
             100%;
    
            .top {
                height: 200px;
                 100%;
                background: red;
            }
    
            .center {
                height: 200px;
                 100%;
                background: green;
            }
    
            .bottom {
                height: 200px;
                 100%;
                background: blue;
            }
        }
    </style>
  • 相关阅读:
    自己用的,存储代码
    ASCII编码表
    全球最热门编程语言20种
    C++中二维数组new小结
    字符,字节和编码
    让工资涨的快的小技巧
    Ip Messenger
    xajax中文手册
    BitmapFile Formats(BMP文件的格式)
    python中返回字符串中指定字符的索引
  • 原文地址:https://www.cnblogs.com/Alex-Song/p/12157616.html
Copyright © 2011-2022 走看看