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

Detailed tutorial on MySql installation and uninstallation

This article shares the tutorial of MySql install...

Sublime Text - Recommended method for setting browser shortcut keys

It is common to view code effects in different br...

Docker case analysis: Building a Redis service

Table of contents 1 Create mount directories and ...

XHTML 1.0 Reference

Arrange by functionNN : Indicates which earlier ve...

Execute the shell or program inside the Docker container on the host

In order to avoid repeatedly entering the Docker ...

Detailed explanation of docker entrypoint file

When writing a Dockerfile, include an entrypoint ...

js to realize web music player

This article shares simple HTML and music player ...

Simple implementation method of two-way data binding in js project

Table of contents Preface Publish-Subscriber Patt...

A brief discussion on the placement of script in HTML

I used to think that script could be placed anywh...

The difference between key and index in MySQL

Let's look at the code first: ALTER TABLE rep...

Pure CSS3 mind map style example

Mind Map He probably looks like this: Most of the...

Detailed explanation of JavaScript to monitor route changes

Table of contents history pushState() Method push...

MySQL max_allowed_packet setting

max_allowed_packet is a parameter in MySQL that i...

Implementation of JavaScript downloading linked images and uploading them

Since we are going to upload pictures, the first ...