VUE PC端可拖动悬浮按钮改进

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>

在这里插入图片描述

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

唐飞滚滚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值