Home  >  Article  >  Web Front-end  >  How to implement custom toast in WeChat mini program

How to implement custom toast in WeChat mini program

亚连
亚连Original
2018-06-23 17:38:031463browse

This article mainly introduces the implementation method of custom toast in WeChat applet, briefly describes the use of toast that comes with WeChat applet, and analyzes the definition and use of custom toast in the form of examples. Friends in need can refer to it. Next

The example in this article describes the implementation method of custom toast in WeChat applet. Share it with everyone for your reference, the details are as follows:

1. WeChat official default toast

toast is the most common, almost every App has it There is such a special effect. Let’s take a look at the toast effect that comes with the mini program. I immediately want to die~~

The toast effect that comes with WeChat:

js file:

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

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

can only display two icons: success and loading

and 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 not simple to implement. How to achieve it:

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


2) JS mainly has the following usage

Core code:

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

This code is the core. getCurrentPages().length - 1 means that the page of the current page can be obtained. Only when the page is obtained can it be set through page.setData The data of the current page is bound to the toast.

Core code:

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

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

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to implement the side sliding menu effect in vue swiper

How to implement the triangular arrow labeling function using Angular

How to implement the timer function using Angular

How to implement the delay hiding function through JS

The above is the detailed content of How to implement custom toast in WeChat mini program. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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