VUE PC端可拖动悬浮按钮改进
之前发过一篇悬浮球的,但是那个不太好用,鼠标移动过快会脱标,就很难受,最近又改了一下,这是加了个监听,拖动结束的时候改变top和left,应该还能改进,欢迎大佬们提出意见
完整代码
<template>
<div>
<div class="sssss">
<div
id="draggable"
@mouseleave="out"
@mouseenter="over"
@click="onClick"
draggable="true"
class="callback float"
ref="fu"
:class="bg == 1 ? 'bg1' : 'bg2'"
>
<div class="numBox" v-if="numNews != 0">
{{ numNews }}
</div>
</div>
</div>
<el-dialog title="" :visible.sync="show_news" width="750px">
<div class="flex boxNews">
<div
class="left"
style="background-color: #ff675d"
v-if="form.jpcd == 2"
>
急
</div>
<div
class="left"
style="background-color: #3da1ff"
v-if="form.jpcd == 1"
>
普
</div>
<div class="right" style="width: 650px">
<div>
<div class="dateInfo">
{{ parseTime(form.createTime, "{y}-{m}-{d}") }}
</div>
<div class="titleInfoNews" style="margin-top: 5px">
{{ form.txbt }}
</div>
<div class="contuntInfoNews" style="margin-top: 5px">
{{ form.txnr }}
</div>
<div style="margin-top: 5px">
<span
class="router"
@click="
show_news = false;
drawer = false;
"
>
<router-link :to="form.tzly + '?' + form.lycs">
点击直达
</router-link>
</span>
</div>
</div>
</div>
</div>
</el-dialog>
<el-drawer
title=""
:visible.sync="drawer"
:with-header="false"
:modal="false"
size="20%"
>
<div style="padding-left: 10px; padding-top: 20px">
<div class="boxNews2">
<div class="titlea">消息</div>
<div>
<div
class="flex boxNews"
v-for="(item, index) in tixxxList"
:key="index"
@click="handleUpdate(item)"
>
<div
class="left"
style="background-color: #ff675d"
v-if="item.jpcd == 2"
>
急
<div class="red" v-if="item.txzt == 1"></div>
</div>
<div class="left" style="background-color: #3da1ff" v-else>
普
<div class="red" v-if="item.txzt == 1"></div>
</div>
<div class="right flex">
<div>
<div class="titleNews">
{{ item.txbt }}
</div>
<div class="contuntNews">
{{ item.txnr }}
</div>
</div>
<div class="date">
{{ parseTime(item.createTime, "{y}-{m}-{d}") }}
</div>
</div>
</div>
</div>
</div>
<el-divider></el-divider>
<div class="titlea">
快捷导航 <i style="color: #409eff" class="el-icon-setting"></i>
</div>
<div class="boxa">
<div
class="item"
style="
background: linear-gradient(150deg, #accaff 0%, #3b88ec 100%);
"
>
基础表统计
</div>
<div
class="item"
style="
background: linear-gradient(150deg, #e8d6ff 0%, #9f55ff 100%);
"
>
分产业统计
</div>
<div
class="item"
style="
background: linear-gradient(150deg, #fdda45 0%, #fe6b62 100%);
"
>
周报
</div>
<div
class="item"
style="
background: linear-gradient(150deg, #cefbc8 0%, #00aec5 100%);
"
>
自营投资项目台账
</div>
<div
class="item"
style="
background: linear-gradient(150deg, #c5f8e6 0%, #10a465 100%);
"
>
项目进度台账
</div>
</div>
</div>
</el-drawer>
</div>
</template>
<script>
export default {
name: "suspensionBall",
data() {
return {
numNews: 0,
drawer: false,
show_news: false,
bg: 1,
isLoading: false,
// 提醒表格数据
tixxxList: [
{
baseId: null,
createBy: "admin",
createTime: "2022-10-21 13:58:33",
delFlag: "0",
hideFieldJson: null,
id: "51161858994b47cc94f965c830d762ec",
jpcd: "2",
lx: "2",
lycs: null,
remark: null,
searchValue: null,
tiaojJson: null,
tiaojList: null,
txbt: "企业风险提醒",
txnr: "内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容",
txzt: "2",
tzly: null,
updateBy: null,
updateTime: "2022-12-05 11:29:47",
userId: "1",
},
],
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 5,
orderByColumn: "createTime",
isAsc: "descending",
lx: null,
jpcd: null,
txbt: null,
txnr: null,
txzt: null,
userId: null,
tzly: null,
lycs: null,
delFlag: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
},
// 表单参数
form: {},
news: null,
};
},
mounted() {
const obj = document.querySelector("#draggable");
obj.addEventListener("dragend", (event) => {
obj.style.left = event.x - 40 + "px";
obj.style.top = event.y - 40 + "px";
if (event.y < 0) {
obj.style.top = 0 + "px";
}
});
},
methods: {
// 表单重置
reset() {
this.form = {
id: null,
lx: null,
jpcd: null,
txbt: null,
txnr: null,
txzt: null,
userId: null,
tzly: null,
lycs: null,
delFlag: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
};
this.resetForm("form");
},
handleUpdate(row) {
if (row.txzt == 2) {
this.reset();
const id = row.id || this.ids;
} else {
}
},
/** 查询提醒列表 */
getList2() {
var that = this;
},
getList() {
var that = this;
},
out() {
this.bg = 2;
},
over() {
this.bg = 1;
},
onClick() {
this.drawer = true;
},
},
};
</script>
<style scoped>
.numBox {
color: #fff;
width: 20px;
height: 20px;
text-align: center;
background-color: red;
line-height: 20px;
border-radius: 50%;
margin-left: 50px;
margin-top: 10px;
}
.boxNews2 {
height: 400px;
}
.router {
color: #409eff;
}
.contuntInfoNews {
color: #585858;
}
.dateInfo {
color: #7a7a7a;
}
.red {
width: 13px;
height: 13px;
border-radius: 50%;
right: 0;
top: 0;
position: absolute;
background-color: red;
border: #fff 2px solid;
}
.date {
font-size: 14px;
margin-left: 10px;
padding-top: 24px;
color: #7a7a7a;
}
.right {
justify-content: space-between;
margin-left: 15px;
}
.left {
position: relative;
color: #fff;
font-weight: bold;
font-size: 20px;
border-radius: 50%;
width: 45px;
height: 45px;
text-align: center;
line-height: 45px;
}
.titleNews {
width: 150px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #575656;
margin-bottom: 5px;
font-size: 14px;
}
.contuntNews {
width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #7a7a7a;
font-size: 13px;
}
.boxNews {
margin-top: 20px;
}
.flex {
display: flex;
}
.bg1 {
background-image: url("../../assets/images/icon1.png");
}
.bg2 {
background-image: url("../../assets/images/icon2.png");
}
.callback {
position: fixed;
width: 80px;
height: 80px;
background-repeat: no-repeat;
background-size: 100% 100%;
top: 50px;
left: 94%;
z-index: 999;
}
.float {
position: fixed;
touch-action: none;
text-align: center;
border-radius: 24px;
line-height: 48px;
color: white;
}
.sssss {
position: relative;
background-color: #000;
right: 0;
z-index: 999;
}
.titlea {
font-size: 18px;
font-family: Microsoft YaHei-Bold, Microsoft YaHei;
font-weight: bold;
color: #333333;
}
.boxa {
display: flex;
flex-wrap: wrap;
margin-top: 20px;
z-index: 999;
}
.item {
margin-bottom: 7px;
width: 168px;
height: 55px;
border-radius: 4px 4px 4px 4px;
font-size: 16px;
font-family: Microsoft YaHei-Bold, Microsoft YaHei;
font-weight: bold;
color: #ffffff;
text-align: center;
margin-left: 7px;
line-height: 55px;
}
</style>
<style lang="scss" scoped>
.note {
cursor: pointer;
position: absolute;
left: 0;
top: 0;
z-index: 9999999;
color: rgba(#000, 0.8);
background-color: rgb(255, 222, 30);
background-image: linear-gradient(
160deg,
rgb(255, 222, 30) 50%,
rgb(255, 250, 80)
);
width: 200px;
min-height: 160px;
padding-top: 20px;
text-align: center;
font-family: "marker felt", "comic sans ms", sans-serif;
font-size: 24px;
line-height: 1.3;
padding: 1em;
box-sizing: border-box;
transform: rotate(-1deg);
transition: all 0.3s ease;
&:before {
cursor: pointer;
content: "";
display: block;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: rgb(180, 8, 0);
background-image: radial-gradient(
at 60% 30%,
#f99,
red 20%,
rgb(180, 8, 0)
);
background-position: 20% 10%;
position: absolute;
top: 0;
left: 90px;
pointer-events: none;
transform: scale(0.8);
box-shadow: -5px 10px 3px -8.5px #000, -1px 7px 12px -5px #000;
transition: all 0.3s ease;
}
}
textarea:hover ~ .note {
&:before {
transform: scale(0.9);
box-shadow: -5px 10px 6px -8.5px #000, -1px 7px 16px -4px #000;
}
}
textarea:active ~ .note {
transform: scale(1.05) rotate(-2deg);
box-shadow: 0 -20px 0 rgb(255, 222, 30), -5px 14px 14px rgba(0, 0, 0, 0.3);
}
</style>