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

Analysis of centos6 method of deploying kafka project using docker

This article describes how to use docker to deplo...

Solution to forgetting the administrator password of mysql database

1. Enter the command mysqld --skip-grant-tables (...

Detailed explanation of loop usage in javascript examples

I was bored and sorted out some simple exercises ...

HTML table tag tutorial (19): row tag

The attributes of the <TR> tag are used to ...

MySQL 8.0.17 installation graphic tutorial

This article shares with you the MySQL 8.0.17 ins...

js to realize the mouse following game

This article shares the specific code of js to im...

Solution to EF (Entity Framework) inserting or updating data errors

Error message: Store update, insert, or delete st...

Semantics, writing, and best practices of link A

The semantics, writing style, and best practices ...

Tutorial on installing MySQL 5.7.18 using RPM package

system: CentOS 7 RPM packages: mysql-community-cl...

Solution to the lack of my.ini file in MySQL 5.7

What is my.ini? my.ini is the configuration file ...

Public free STUN servers

Public free STUN servers When the SIP terminal us...

Vue parent-child component mutual value transfer and call

Table of contents 1. Parent passes value to child...

Sample code for implementing neon button animation effects with CSS3.0

Today I will share with you a neon button animati...

Simplify complex website navigation

<br />Navigation design is one of the main t...