Detailed explanation of the implementation method of custom toast in WeChat applet

小云云
Release: 2017-12-07 15:53:11
Original
2842 people have browsed it

We have shared many tutorials about WeChat mini programs before. In this article, we mainly introduce the implementation method of custom toast in WeChat mini programs, briefly describe the use of toast that comes with WeChat mini programs, and analyze the definition of custom toast in the form of examples. Friends in need can refer to the usage method.

1. WeChat’s official default toast

Toast is the most common. Almost every App has such special effects. Let’s take a look at the mini program first. The built-in toast effect makes me want to die immediately~~

The toast effect that comes with WeChat:

js file:


wx.showToast({ title: '成功', icon: 'success', duration: 2000 })
Copy after login


The usage is super simple, but the official mini program has several problems:

can only display two icons: success and loading.

And the icon cannot be removed

The maximum duration is 10 seconds

2. Custom toast

Our most common toast is towards the bottom, and the height is relatively small~~

Look at the effect first:

It seems simple, but it is implemented It is quite not simple. How to implement it:

1) Create a public toast template file, because every page needs to use toast


 
Copy after login


2) JS mainly has the following usage

Core code:


let pages = getCurrentPages(); let curPage = pages[pages.length - 1];
Copy after login


This code is the core.getCurrentPages().length - 1means that the page of the current page can be obtained. Only by obtaining the page can the data of the current page be bound throughpage.setDatato the toast.

Core code:


let animation = wx.createAnimation(); animation.opacity(1).step();
Copy after login


This code has a slow animation effect when the toast disappears.

Related recommendations:

How to dynamically modify label transparency in the WeChat applet slider component

How to implement the image enlargement preview function in the WeChat applet

New function of customizing pictures when sharing in WeChat applet

The above is the detailed content of Detailed explanation of the implementation method of custom toast in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!