


A brief analysis of how to make scroll-view scroll according to the specified position in the mini program
This article will introduce to you how to make the scroll-view scroll according to the specified position in the WeChat applet. You can get an excellent experience without writing additional js scripts. I hope it will be helpful to everyone!
The background is like this. The WeChat applet has a tab
switching page, and the tab
switching page has two content boxes. I use scroll-view
to make it, and then when switching the tab
page, the corresponding scroll bar in scroll-view
needs to be on top. [Related learning recommendations: 小program development tutorial]
We can see that there is a scroll-into-view# in the official document description
scroll-view ##Attribute, the description of this attribute is as follows
The value of scroll-into-view should be a certain sub-element id (the id cannot start with a number). Set which direction can be scrolled, then scroll to the element in which direction
Then we can make a fuss about this attribute, just put an id value inscroll-view By setting a custom value, when switching
tab, the corresponding content box scroll bars will automatically scroll to the top, as shown in the following code. The following code is what I use
Taro The program framework demonstrates the same as the native one.
import Taro from '@tarojs/taro' import { View } from '@tarojs/components' import { AtTabs, AtTabsPane } from 'taro-ui' export default class Index extends Taro.Component { constructor () { super(...arguments) this.state = { current: 0, } } handleClick (value) { this.setState({ current: value }) } render () { const tabList = [{ title: '标签第一页' }, { title: '标签第二页' }, { title: '标签第三页' }] return ( <AtTabs current={this.state.current} tabList={tabList} onClick={this.handleClick.bind(this)}> <AtTabsPane current={this.state.current} index={0} > <ScrollView scrollY scrollIntoView='content-0'> <View id='content-0'></View> 标签页一的内容 </ScrollView> </AtTabsPane> <AtTabsPane current={this.state.current} index={1} > <ScrollView scrollY scrollIntoView='content-1'> <View id='content-1'></View> 标签页二的内容 </ScrollView> </AtTabsPane> <AtTabsPane current={this.state.current} index={2} > <ScrollView scrollY scrollIntoView='content-2'> <View id='content-2'></View> 标签页三的内容 </ScrollView> </AtTabsPane> </AtTabs> ) } }
view## with the ID value content-0
in the scroll-view
of the first tab
#, then when switching the tab
page, scroll-view
will be positioned on the id of the child element according to the scroll-into-view
attribute we set, and reach The effect of the scroll bar automatically moving to the top<div class="code" style="position:relative; padding:0px; margin:0px;"><pre class='brush:php;toolbar:false;'><AtTabsPane current={this.state.current} index={0} >
<ScrollView scrollY scrollIntoView=&#39;content-0&#39;>
<View id=&#39;content-0&#39;></View>
标签页一的内容
</ScrollView>
</AtTabsPane></pre><div class="contentsignin">Copy after login</div></div>
Similarly, if you need the scroll bar to scroll to the lowest position, just put the corresponding sub-element ID to the lowest position. For example, in some chat interfaces, you need to locate the latest one. Article
<AtTabsPane current={this.state.current} index={0} > <ScrollView scrollY scrollIntoView='content-0'> 标签页一的内容 <View id='content-0'></View> </ScrollView> </AtTabsPane>
For more programming-related knowledge, please visit:
Programming VideoThe above is the detailed content of A brief analysis of how to make scroll-view scroll according to the specified position in the mini program. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the popularity of mobile Internet technology and smartphones, WeChat has become an indispensable application in people's lives. WeChat mini programs allow people to directly use mini programs to solve some simple needs without downloading and installing applications. This article will introduce how to use Python to develop WeChat applet. 1. Preparation Before using Python to develop WeChat applet, you need to install the relevant Python library. It is recommended to use the two libraries wxpy and itchat here. wxpy is a WeChat machine

How to implement the function of scrolling to a specified element position in JavaScript? In a web page, when we need to focus the user's line of sight to a specific element position, we can use JavaScript to implement the function of scrolling to the specified element position. This article will introduce how to implement this function through JavaScript and provide corresponding code examples. First, we need to obtain the position information of the target element. You can use Element.getBoundingClient

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: <!--index.wxml-->&l

Mini programs can use react. How to use it: 1. Implement a renderer based on "react-reconciler" and generate a DSL; 2. Create a mini program component to parse and render DSL; 3. Install npm and execute the developer Build npm in the tool; 4. Introduce the package into your own page, and then use the API to complete the development.

According to news from this site on October 31, on May 27 this year, Ant Group announced the launch of the "Chinese Character Picking Project", and recently ushered in new progress: Alipay launched the "Chinese Character Picking-Uncommon Characters" mini program to collect collections from the society Rare characters supplement the rare character library and provide different input experiences for rare characters to help improve the rare character input method in Alipay. Currently, users can enter the "Uncommon Characters" applet by searching for keywords such as "Chinese character pick-up" and "rare characters". In the mini program, users can submit pictures of rare characters that have not been recognized and entered by the system. After confirmation, Alipay engineers will make additional entries into the font library. This website noticed that users can also experience the latest word-splitting input method in the mini program. This input method is designed for rare words with unclear pronunciation. User dismantling

How to monitor the scrolling of an iframe requires specific code examples. When we use the iframe tag to embed other web pages in a web page, sometimes we need to perform some specific operations on the content in the iframe. One of the common needs is to listen for the scroll event of the iframe so that the corresponding code can be executed when the scroll occurs. The following will introduce how to use JavaScript to monitor the scrolling of an iframe, and provide specific code examples for reference. Get the iframe element First, we need

How uniapp can achieve rapid conversion between mini programs and H5 requires specific code examples. In recent years, with the development of the mobile Internet and the popularity of smartphones, mini programs and H5 have become indispensable application forms. As a cross-platform development framework, uniapp can quickly realize the conversion between small programs and H5 based on a set of codes, greatly improving development efficiency. This article will introduce how uniapp can achieve rapid conversion between mini programs and H5, and give specific code examples. 1. Introduction to uniapp unia

HTML, CSS and jQuery: Make an automatically scrolling bulletin board In modern web design, bulletin boards are often used to convey important information and attract user attention. An auto-scrolling bulletin board is widely used on web pages. It allows the bulletin content to scroll and display on the page in the form of animation, improving the information display effect and user experience. This article will introduce how to use HTML, CSS and jQuery to make an automatic scrolling bulletin board, and provide specific code examples. First, we need a HT
