Example of how to achieve ceiling effect using WeChat applet

Example of how to achieve ceiling effect using WeChat applet

The background is a date title. As the user slides, there is a ceiling effect when sliding to the current date list data, and this effect is different from the original style.

1. Implementation

  • Scroll-view is a native component of the mini program
  • handleScroll is the event triggered when sliding
  • scroll-y means that sliding is allowed in the vertical direction
  • The element with class fixed is fixed here at the top of the scroll-view container to display the current date.
  • Use the dynamic binding class method to control the display of visibility
  • The element with class scheduleDay is the title of each date.
  • The value of data-value is bound to the date

  • This function processes the data of each scheduleDay element's distance from the top of the scroll-view and the current date.
  • The data is collected as follows and so on
  • wx.createSelectorQuery() usage details (generally used to obtain the location information of an element node)
  • developers.weixin.qq.com/miniprogram…
scheduleInfo:[
    {
       top: 8,
       currentDay: '2021-08-15'
    },
    {
       top: 213,
       currentDay: '2021-08-14'
    },
    {
       top: 555,
       currentDay: '2021-08-13'
    },
    ...
]

  • e.detail.scrollTop is the sliding distance in the scroll-view component
  • When the sliding height >= the distance between a certain element node and the top of the scrollview, set the current sliding date
  • Then you can control the appearance or hiding of fixed positioned elements to achieve

This article will not show too much about CSS, the functional effect can be achieved as long as the logical thinking is correct

2. Problems

  • Due to the error in the frequency of triggering the handleScroll sliding event, the fixed element is not hidden when sliding to the top
  • When pulling up, the fixed element and the date title at the original position will have a bad UI experience
  • Refer to the following figure

This figure shows the default UI display

The UI display when the user slides to the list position under the date, or the situation where the first point of the problem exists

Then it will affect the second point of the problem

3. Consider whether there is a better way to implement it

The first idea was to dynamically add a corresponding class to the date title of each element node to control the change of individual styles, but the class of each element is the same and this method cannot be used to solve it.

Modification is done by controlling the style of each individual element node, but unlike the DOM in the browser, the mini program cannot change the style of each individual element through dom.style.xxx.

IntersectionObserver, this method has also been tried, but it didn’t work. I’ll try it again when I have a chance.

Summarize

This is the end of this article about how to achieve ceiling effects with WeChat mini-programs. For more content related to ceiling effects with mini-programs, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • WeChat applet achieves simple ceiling effect
  • WeChat applet achieves simple ceiling effect
  • WeChat applet implements sample code for list scrolling head ceiling
  • Mini Program custom template to achieve ceiling function
  • WeChat applet wxs achieves ceiling effect
  • WeChat applet realizes ceiling effect
  • WeChat applet achieves ceiling effect
  • Mini program to achieve simple ceiling effect

<<:  MySQL slow query operation example analysis [enable, test, confirm, etc.]

>>:  How to change the system language of centos7 to simplified Chinese

Recommend

Solution to mysql error code 1064

If the words in the sql statement conflict with t...

Example of how to import nginx logs into elasticsearch

The nginx logs are collected by filebeat and pass...

How to optimize MySQL query speed

In the previous chapters, we introduced how to ch...

Summary of MySQL Architecture Knowledge Points

1. Databases and database instances In the study ...

Why MySQL can ignore time zone issues when using timestamp?

I have always wondered why the MySQL database tim...

How to disable foreign key constraint checking in MySQL child tables

Prepare: Define a teacher table and a student tab...

Solution to Nginx 500 Internal Server Error

Today, when I was using Nginx, a 500 error occurr...

Solution to the bug that IE6 select cannot be covered by div

Use div to create a mask or simulate a pop-up wind...

js uses cookies to remember user page operations

Preface During the development process, we someti...

Enterprise-level installation tutorial using LAMP source code

Table of contents LAMP architecture 1.Lamp Introd...

How to solve the problem of case insensitivity in MySQL queries

question Recently, when I was completing a practi...

How to add sudo permissions to a user in Linux environment

sudo configuration file The default configuration...

HTML meta viewport attribute detailed description

What is a Viewport Mobile browsers place web pages...

W3C Tutorial (16): Other W3C Activities

This section provides an overview of some other i...