


Teach you step by step how to implement floating buttons in mini programs (code example)
How to implement floating buttons in mini programs? The following article will introduce to you how to implement the floating button function in a mini program. I hope it will be helpful to you!
In daily small program development, we may have such a need to suspend the button and not change the position as the page slides, such as the article details page I want to make the sharing button floating, or set a floating button on the homepage to implement some scalable functions, which is both beautiful and convenient.
I will explain how to implement the floating button from two aspects , one is to implement the picture button, and the other is to float the button. [Related learning recommendations: Mini Program Development Tutorial]
Image Button Implementation
In the button component provided by the mini program, there is no function to separately set pictures into buttons. Although the mini program does not have natural component support, we can achieve this effect ourselves
First code
Page code
<!--pages/content-detail/content-detail.wxml--> <button plain='true' class="circle"> <image mode='aspectFill' src='/images/icon/collect.png' class='image'></image> </button>
css style code
.circle[plain] { padding: 0; border: none; width: 64rpx; height: 64rpx; } .image { width: 64rpx; height: 64rpx; }
circle is the class of button, image is the class of picture
The code is very simple, Xiaodan will explain the above code for everyone
- ##Hide Display of the buttonWe want to display the picture, and the button is packaged with the picture, so we need to hide the button,
plain='true' This attribute can be achieved.
- Hide the border of the buttonIn addition to hiding the button, you also need to hide its border. The corresponding css style is:
border: none , please note here that [plain]
must be added to the css class. For example,.circle[plain], otherwise the border may not disappear.
- Alignment of pictures and buttonsThe size of the picture needs to be consistent with the size of the button. In order to achieve alignment, the css style in the button must be set
padding: 0
.circle[plain] { display: flex; margin-right: 40rpx; right: 0; position: fixed; bottom: 15%; padding: 0; border: none; width: 64rpx; height: 64rpx; }position is a position attribute, which has many different values. Let’s take a look at the official definition of fixed
is not an element Instead of leaving space, you specify element position by specifying its position relative to the screen's viewport. The element's position does not change when the screen scrolls. When printing, the element will appear at a fixed location on each page. The fixed attribute creates a new stacking context. When the transform attribute of an element's ancestor is non-none, the container is changed from the viewport to that ancestor.We have fully implemented the code for the floating button. Let’s take a look at the specific effect
Programming Video! !
The above is the detailed content of Teach you step by step how to implement floating buttons in mini programs (code example). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software