最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue項(xiàng)目實(shí)現(xiàn)按鈕可隨意移動(dòng)

 更新時(shí)間:2022年03月30日 08:51:15   作者:帥_帥  
這篇文章主要為大家詳細(xì)介紹了vue項(xiàng)目實(shí)現(xiàn)按鈕可隨意移動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

vue項(xiàng)目中實(shí)現(xiàn)按鈕可隨意移動(dòng),供大家參考,具體內(nèi)容如下

組件代碼如下:

在項(xiàng)目中引入該組件即可

<template>
? <div v-show="hide" class="move-button" ref="moveBtn"
? ? ? ?@mousedown="btnDown"
? ? ? ?@touchstart="btnDown"
? ? ? ?@mousemove="btnMove"
? ? ? ?@touchmove="btnMove"
? ? ? ?@mouseup="btnEnd"
? ? ? ?@touchend="btnEnd"
? ? ? ?@touchcancel="btnEnd">
? ? <div class="button-mainbg">
? ? </div>
?? ?</div>
</template>

<script>
export default {
? ? name: 'MoveButton',
? ? data() {
? ? ? ? return {
? ? ? ? ? ? hide: true,
? ? ? ? ? ? img: require('@/assets/img/moveButton.png'),
? ? ? ? ? ? flags: false,
? ? ? ? ? ? position: {
? ? ? ? ? ? ? ? x: 0,
? ? ? ? ? ? ? ? y: 0
? ? ? ? ? ? },
? ? ? ? ? ? nx: '',
? ? ? ? ? ? ny: '',
? ? ? ? ? ? dx: '',
? ? ? ? ? ? dy: '',
? ? ? ? ? ? xPum: '',
? ? ? ? ? ? yPum: '',
? ? ? ? ? ? isShow: false,
? ? ? ? ? ? moveBtn: {},
? ? ? ? ? ? timer: null,
? ? ? ? ? ? currentTop:0
? ? ? ? }
? ? },
? ? mounted() {
? ? ? ? this.moveBtn = this.$refs.moveBtn;
? ? ? ? window.addEventListener('scroll', this.hideButton);
? ? },
? ? beforeDestroy() {
? ? ? ? window.addEventListener('scroll', this.hideButton);
? ? },
? ? methods: {
? ? ? ? hideButton() {
? ? ? ? ? ? this.timer&&clearTimeout(this.timer);
? ? ? ? ? ? this.timer = setTimeout(()=>{
? ? ? ? ? ? ?this.handleScrollEnd();
? ? ? ? ? ? },300);
? ? ? ? ? ? this.currentTop = document.documentElement.scrollTop || document.body.scrollTop;
? ? ? ? ? ? this.hide = false;
? ? ? ? },
? ? ? ? handleScrollEnd(){
? ? ? ? ? ? let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
? ? ? ? ? ? if(scrollTop === this.currentTop){
? ? ? ? ? ? this.hide = true;
? ? ? ? ? ? clearTimeout(this.timer);
? ? ? ? ? ? }
? ? ? ? },

? ? ? ? // 實(shí)現(xiàn)移動(dòng)端拖拽
? ? ? btnDown() {
? ? ? ? ? ? this.flags = true;
? ? ? ? ? ? let touch;
? ? ? ? ? ? if (event.touches) {
? ? ? ? ? ? ? ? touch = event.touches[0];
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? touch = event;
? ? ? ? ? ? }
? ? ? ? ? ? this.position.x = touch.clientX;
? ? ? ? ? ? this.position.y = touch.clientY;
? ? ? ? ? ? this.dx = this.moveBtn.offsetLeft;
? ? ? ? ? ? this.dy = this.moveBtn.offsetTop;
? ? ? ? },
? ? ? btnMove() {
? ? ? ? ? ? if (this.flags) {
? ? ? ? ? ? ? ? let touch;
? ? ? ? ? ? ? ? if (event.touches) {
? ? ? ? ? ? ? ? ? ? touch = event.touches[0];
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? touch = event;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? this.nx = touch.clientX - this.position.x;
? ? ? ? ? ? ? ? this.ny = touch.clientY - this.position.y;
? ? ? ? ? ? ? ? this.xPum = this.dx + this.nx;
? ? ? ? ? ? ? ? this.yPum = this.dy + this.ny;
? ? ? ? ? ? ? ? let clientWidth = document.documentElement.clientWidth;
? ? ? ? ? ? ? let clientHeight = document.documentElement.clientHeight;
? ? ? ? ? ? ? ? if (this.xPum > 0 && this.xPum < (clientWidth - this.moveBtn.offsetWidth)) {
? ? ? ? ? ? ? ? ? ? this.moveBtn.style.left = this.xPum + "px";
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (this.yPum > 0 && this.yPum < (clientHeight - this.moveBtn.offsetHeight)) {
? ? ? ? ? ? ? ? ? ? this.moveBtn.style.top = this.yPum + "px";
? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? //阻止頁面的滑動(dòng)默認(rèn)事件
? ? ? ? ? ? ? ? document.addEventListener("touchmove", this.handler, {
? ? ? ? ? ? ? ? ? ? passive: false
? ? ? ? ? ? ? ? });
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? //鼠標(biāo)釋放時(shí)候的函數(shù)
? ? ? ? btnEnd() {
? ? ? ? ? ? this.flags = false;
? ? ? ? ? ? document.addEventListener('touchmove', this.handler, {
? ? ? ? ? ? ? ? passive: false
? ? ? ? ? ? });
? ? ? ? },
? ? ? ? handler(e) {
? ? ? ? ? ? if(this.flags){
? ? ? ? ? ? ? ? event.preventDefault();
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? return true
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
</script>

<style lang="stylus" scoped>
.move-button {

? ? border-radius:50%;
? ? width: 50px;
? ? height: 50px;
? ? position: fixed;
? ? z-index: 10;

? color: #FFF;

? .button-mainbg{
? ? position: relative;
? ? width:50px;
? ? height:50px;
? ? border-radius:50%;
? ? background: url("../../assets/img/moveButton.png") no-repeat;
? ? background-size: 50px 50px;
? }


}
</style>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Vue基于vue-quill-editor富文本編輯器使用心得

    詳解Vue基于vue-quill-editor富文本編輯器使用心得

    這篇文章主要介紹了Vue基于vue-quill-editor富文本編輯器使用心得,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-01-01
  • vue實(shí)現(xiàn)拖拽滑動(dòng)分割面板

    vue實(shí)現(xiàn)拖拽滑動(dòng)分割面板

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)拖拽滑動(dòng)分割面板,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • 關(guān)于Element?table組件滾動(dòng)條不顯示的踩坑記錄

    關(guān)于Element?table組件滾動(dòng)條不顯示的踩坑記錄

    這篇文章主要介紹了關(guān)于Element?table組件滾動(dòng)條不顯示的踩坑記錄,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • Vue+Element UI實(shí)現(xiàn)概要小彈窗的全過程

    Vue+Element UI實(shí)現(xiàn)概要小彈窗的全過程

    彈窗效果是我們?nèi)粘i_發(fā)中經(jīng)常遇到的一個(gè)功能,下面這篇文章主要給大家介紹了關(guān)于Vue+Element UI實(shí)現(xiàn)概要小彈窗的相關(guān)資料,需要的朋友可以參考下
    2021-05-05
  • Vue.js中的computed功能設(shè)計(jì)

    Vue.js中的computed功能設(shè)計(jì)

    computed作為計(jì)算屬性其作用是描述響應(yīng)式數(shù)據(jù)的復(fù)雜邏輯計(jì)算,當(dāng)所依賴的響應(yīng)式數(shù)據(jù)發(fā)生改變時(shí)計(jì)算屬性會(huì)重新計(jì)算,更新邏輯計(jì)算的結(jié)果,這篇文章主要介紹了Vue.js中的computed的功能設(shè)計(jì),需要的朋友可以參考下
    2023-06-06
  • 一文帶你了解什么是Vue?Vapor

    一文帶你了解什么是Vue?Vapor

    隨著Svelte和SolidJS的流行,無虛擬DOM模式逐漸開始火了起來,Vue?Vapor就是一個(gè)無虛擬DOM模式版本的vue,下面就跟隨小編一起來深入了解一下Vue?Vapor吧
    2024-11-11
  • VUE開發(fā)分布式醫(yī)療掛號(hào)系統(tǒng)后臺(tái)管理頁面步驟

    VUE開發(fā)分布式醫(yī)療掛號(hào)系統(tǒng)后臺(tái)管理頁面步驟

    本文從整體上介紹Vue框架的開發(fā)流程,結(jié)合具體的案例,使用Vue框架調(diào)用具體的后端接口,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-04-04
  • Vue+Axios實(shí)現(xiàn)文件上傳自定義進(jìn)度條

    Vue+Axios實(shí)現(xiàn)文件上傳自定義進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了Vue+Axios實(shí)現(xiàn)文件上傳自定義進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • vue實(shí)現(xiàn)同時(shí)設(shè)置多個(gè)倒計(jì)時(shí)

    vue實(shí)現(xiàn)同時(shí)設(shè)置多個(gè)倒計(jì)時(shí)

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)同時(shí)設(shè)置多個(gè)倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-05-05
  • Vue項(xiàng)目中如何引入本地第三方JS庫

    Vue項(xiàng)目中如何引入本地第三方JS庫

    vue中常遇到第三方j(luò)s,這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目中如何引入本地第三方JS庫的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06

最新評(píng)論

长岛县| 丁青县| 谢通门县| 钟山县| 安达市| 井陉县| 微博| 昭通市| 万宁市| 白河县| 巩义市| 越西县| 苏州市| 东阳市| 察雅县| 渑池县| 菏泽市| 微山县| 周宁县| 会宁县| 光山县| 商河县| 澄城县| 南通市| 兴宁市| 泌阳县| 镇坪县| 遵化市| 武宁县| 班玛县| 绥芬河市| 彝良县| 称多县| 芮城县| 永泰县| 北流市| 中牟县| 乐业县| 金阳县| 大化| 醴陵市|