Home > Web Front-end > uni-app > How to make moving icons in uniapp

How to make moving icons in uniapp

藏色散人
Release: 2020-12-17 16:39:55
Original
4094 people have browsed it

How to make moving icons in uniapp: first open the html code file; then set the drag element movable in uni-app; finally set the "pointer-events" attribute in the css style to make it draggable moving floating icon.

How to make moving icons in uniapp

The operating environment of this tutorial: windows7 system, uni-app2.5.1 version. This method is suitable for all brands of computers.

Recommendation (free): uni-app development tutorial

uni-app draggable floating icon

There is a requirement in the two projects.

Create a newbie red envelope icon in uni-app, which requires full-screen dragging and a fixed initial position.

The style is like this:

How to make moving icons in uniapp

The following is my solution

1. First of all, there are Special drag element movable, the html code is as follows

<movable-area class="movableArea" v-else-if="isShowPhone==0">
<movable-view class="movableView" direction="all" x="600rpx" y="800rpx">
<image :src="imgurl +&#39;small_hb.png&#39;" mode="widthFix" @click="to_xfj_gg"></image>
<text>余额:¥{{hb_ye}}</text>
</movable-view>
</movable-area>
Copy after login

. movable-view is a draggable element, movable-area is the drag range of the element

2.

The problem occurred. After setting it up, I found that the red envelope can be clicked, but other elements on the page It cannot be clicked because the movable-area blocks other elements and cannot be solved using z-index. After Du Niang’s guidance, pointer-events need to be set in the css style.

css code is as follows

.movableArea {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
            pointer-events: none;//设置area元素不可点击,则事件便会下移至页面下层元素
.movableView {
                pointer-events: auto;//可以点击
width: 120rpx;
height: 110rpx;
image {
width: 100%;
height: 100%;
}
text {
position: absolute;
left: 0;
bottom:0;
width: 120rpx;
height: 18rpx;
display: flex;
justify-content: center;
align-items: center;
font-size: 16rpx;
color: #ffffff;
}
}
}
Copy after login

3. This enables draggable floating icons

The above is the detailed content of How to make moving icons in uniapp. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template