Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report