uniapp使用scroll-view實(shí)現(xiàn)左右上下滑動(dòng)功能
闡述
我們?cè)陧?xiàng)目中往往都能遇到實(shí)現(xiàn)左右滑動(dòng)跟上下滑動(dòng)的需求,不需要安裝 better-scroll uniapp 自帶的scroll-view 就可以實(shí)現(xiàn)了。
實(shí)現(xiàn)左右滑動(dòng)
<view class="model_scrollx flex_row"> <scroll-view class="uni-swiper-tab" scroll-x :style="'height:'+scrollH+'px'"> <view class="scrollx_items"> <button class="guige1 guige-active">蘋果</button> </view> <view class="scrollx_items"> <button class="guige1 guige-active">菠蘿</button> </view> <view class="scrollx_items"> <button class="guige1 guige-active">香蕉</button> </view> </scroll-view> </view> <script> export default { name: "shopping", data() { return { scrollH: 130, // 高度 } }, } </script> <style> /* 二級(jí)菜單設(shè)置左右滑動(dòng) */ .uni-swiper-tab{ white-space: nowrap; } .model_scrollx{ justify-content: space-between; height: 45px; /* background-color: #F1EFEF; */ align-items: center; } .scrollx_items{ text-align: center; display: inline-block; width: 210rpx; box-sizing: border-box; margin-left: 30rpx; margin-top: 3px; } .scrollx_items:last-child{ margin-right: 30rpx; } .scrollx_items image{ width: 70rpx; height: 66rpx; } .tgyx_title{ font-size: 28rpx; color: #333333; margin-top: 30rpx; } .tgyx_desc{ font-size: 24rpx; margin-top: 10rpx; } </style>
實(shí)現(xiàn)上下滑動(dòng)
<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">注冊(cè)地址</view> <view class="scroll-view-item center">注冊(cè)地址</view> <view class="scroll-view-item bottom">注冊(cè)電話</view> </scroll-view> </view> </view> </view> </template> <script> export default { data() { return { } }, methods: { scroll(event) { //距離每個(gè)邊界距離 console.log(event.detail) }, //滾動(dòng)到底部/右邊觸發(fā) scrolltolower() { console.log(123213213213); }, // 滾動(dòng)到頂部/左邊觸發(fā) scrolltoupper() { console.log(2232332); } } } </script> <style> .scroll-view { white-space: nowrap; height: 200px; width: 100%; } .top { height: 200px; width: 100%; background: red; } .center { height: 200px; width: 100%; background: green; } .bottom { height: 200px; width: 100%; background: blue; } </style>
去掉scroll-view的滾動(dòng)條
不能單獨(dú)設(shè)置到style樣式里面,uniapp要設(shè)置到全局App.vue這個(gè)文件下面才可生效。
<style> /* 去除scroll滾動(dòng)條 */ ::-webkit-scrollbar { width: 0; height: 0; background-color: transparent; } </style>
總結(jié)
到此這篇關(guān)于uniapp使用scroll-view實(shí)現(xiàn)左右上下滑動(dòng)功能的文章就介紹到這了,更多相關(guān)uniapp用scroll-view左右上下滑動(dòng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript自定義等待wait函數(shù)實(shí)例分析
這篇文章主要介紹了JavaScript自定義等待wait函數(shù),實(shí)例分析了自定義等待函數(shù)的實(shí)現(xiàn)與使用技巧,需要的朋友可以參考下2015-03-03微信小程序基于slider組件動(dòng)態(tài)修改標(biāo)簽透明度的方法示例
這篇文章主要介紹了微信小程序基于slider組件動(dòng)態(tài)修改標(biāo)簽透明度的方法,可通過slider組件拖動(dòng)實(shí)現(xiàn)圖片透明度的改變功能,涉及微信小程序事件綁定、base64格式圖片載入及slider組件使用技巧,需要的朋友可以參考下2017-12-12如何讓div span等元素能響應(yīng)鍵盤事件操作指南
在我這幾天的工作中遇到了一個(gè)問題,我有一個(gè)可編輯的div,并且在DIV里面還有一個(gè)可編輯的span,我想要讓span能響應(yīng)鍵盤事,想實(shí)現(xiàn)這種效果,應(yīng)該如何實(shí)踐呢2012-11-11three.js實(shí)現(xiàn)3D模型展示的示例代碼
本篇文章主要介紹了three.js實(shí)現(xiàn)3D模型展示的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-12-12js+html5實(shí)現(xiàn)canvas繪制簡單矩形的方法
這篇文章主要介紹了js+html5實(shí)現(xiàn)canvas繪制簡單矩形的方法,涉及html5圖形繪制的基本技巧,需要的朋友可以參考下2015-06-06JavaScript無提示關(guān)閉窗口(兼容IE/Firefox/Chrome)
JavaScript無提示關(guān)閉當(dāng)前頁面窗口,兼容IE/Firefox/Chrome (Close the current page window without confirm by JavaScript, support all browsers)2008-11-11