Get the App
SLTechnology News&Howtos  ›  Development  › 

How does WeChat Mini Programs make the button back to the top?

Shulou Source: shulou.com Published: 2022-05-31 21:14:56 09月30日 Update

This article mainly introduces "how to make the button back to the top by WeChat Mini Programs". In the daily operation, I believe many people have doubts about how to make the button back to the top by WeChat Mini Programs. The editor consulted all kinds of materials and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the question of "how to make the button back to the top by WeChat Mini Programs". Next, please follow the editor to study!

In the first case, the back to top button does not appear when the page is at the top.

In the second case, when the page is a certain distance from the top, the back to the top button appears

Then comes the analysis of the code:

Here we want to use scrolling events, Mini Program stipulates that the outermost layer must be wrapped with a scroll-view tag, and then in setting scroll-y= "true" means allowing the page to scroll vertically, scroll-top is scrolling to the top to do processing, generally binding an event, bindscrolltolower the same principle, scroll to the bottom to do processing, bindscroll means to start when scrolling this event. The following inside WXML is that we go back to the top button setting, and when we click on it, we bind an event goTop so that its scroll height is equal to 0, so it goes back to the top.

WXML Code:

/ / * Top / / *

JS Code:

/ / back to the top button Page ({data: {scrollTop:0}, goTop: function (e) {this.setData ({scrollTop:0})}, scroll:function (eMagneur res) {/ / when the container scrolls, assign the scrolling distance to this.data.scrollTopif (e.detail.scrollTop > 500) {this.setData ({floorstatus: true}) } else {this.setData ({floorstatus: false});}})

WXSS Code:

BigWrap {background:#eee;} / goTop goes back to the top icon start/.com-widget-goTop {position: fixed;bottom: 125pxposition right: 5pxbackground: rgba; border-radius: 50% widget-goTop: hidden;z-index: 500;} .com-widget-goTop. Icon-gotop {background-color: rgba); display: inline-block;width: 50pxposition height: 50pxposition center: 68pxtransfercolor: # ffffff;text-align center: Border-radius: 50% background: url (http://m.dev.vd.cn/static/xcx/v1/goo/w_2-3451cc437e.png) no-repeat center-1110pxty: 50px auto;). At this point, the study on "how to make the button back to the top by WeChat Mini Programs" is over. I hope to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Top button program production event code learning time page that is situation more processing help utility next package principle icon outer layer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei MySQL NVidia MariaDB