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

vue實現(xiàn)移動端可拖拽式icon圖標

 更新時間:2022年03月02日 17:12:37   作者:進了……  
這篇文章主要為大家詳細介紹了vue實現(xiàn)移動端可拖拽式icon圖標,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vue實現(xiàn)移動端可拖拽式icon圖標的具體代碼,供大家參考,具體內(nèi)容如下

需求描述:在移動端頁面懸浮一個可隨便拖拽的圖標,類似于蘋果手機的輔助觸控小圓點,并且可隨意拖動。

預覽:

組件代碼如下:

<template>
? ? <div class="ys-float-btn" :style="{'width':itemWidth+'px','height':itemHeight+'px','left':left+'px','top':top+'px'}"
? ? ? ? ?ref="div"
? ? ? ? ?@click ="onBtnClicked">
? ? ? ? <slot name="icon"></slot>
? ? ? ? <SvgIcon :iconClass="'changjianwentijieda'"
? ? ? ? ? ? ? ? ?:style="{'width':itemWidth+'px','height':itemHeight+'px'}"/>
? ? </div>
</template>
?
?
<script>
? ? export default {
? ? ? ? name: "DragIcon",
? ? ? ? props:{
? ? ? ? ? ? itemWidth:{
? ? ? ? ? ? ? ? type:Number,
? ? ? ? ? ? ? ? default:40
? ? ? ? ? ? },
? ? ? ? ? ? itemHeight:{
? ? ? ? ? ? ? ? type:Number,
? ? ? ? ? ? ? ? default:40
? ? ? ? ? ? },
? ? ? ? ? ? gapWidth:{
? ? ? ? ? ? ? ? type:Number,
? ? ? ? ? ? ? ? default:10
? ? ? ? ? ? },
?
? ? ? ? ? ? coefficientHeight:{
? ? ? ? ? ? ? ? type:Number,
? ? ? ? ? ? ? ? default:0.8
? ? ? ? ? ? }
? ? ? ? },
? ? ? ? created(){
? ? ? ? ? ? this.clientWidth = document.documentElement.clientWidth;
? ? ? ? ? ? this.clientHeight = document.documentElement.clientHeight;
? ? ? ? ? ? this.left = this.clientWidth - this.itemWidth - this.gapWidth;
? ? ? ? ? ? this.top = this.clientHeight*this.coefficientHeight;
? ? ? ? },
? ? ? ? mounted(){
? ? ? ? ? ? this.$nextTick(()=>{
? ? ? ? ? ? ? ? const div = this.$refs.div;
? ? ? ? ? ? ? ? div.addEventListener("touchstart",(e)=>{
? ? ? ? ? ? ? ? ? ? e.stopPropagation();
? ? ? ? ? ? ? ? ? ? div.style.transition = 'none';
? ? ? ? ? ? ? ? });
? ? ? ? ? ? ? ? div.addEventListener("touchmove",(e)=>{
? ? ? ? ? ? ? ? ? ? ? ? e.stopPropagation();
? ? ? ? ? ? ? ? ? ? ? ? if (e.targetTouches.length === 1) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? let touch = event.targetTouches[0];
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.left = touch.clientX - this.itemWidth/2;
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.top = touch.clientY - this.itemHeight/2;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? ? ? false
? ? ? ? ? ? ? ? );
? ? ? ? ? ? ? ? div.addEventListener("touchend",(e)=>{
? ? ? ? ? ? ? ? ? ? e.stopPropagation();
? ? ? ? ? ? ? ? ? ? div.style.transition = 'all 0.3s';
? ? ? ? ? ? ? ? ? ? if(this.left>this.clientWidth/2){
? ? ? ? ? ? ? ? ? ? ? ? this.left = this.clientWidth - this.itemWidth - this.gapWidth;
? ? ? ? ? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? ? ? ? ? this.left = this.gapWidth;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if(this.top<=36)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? this.top=36+this.gapWidth
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? ? ? let bottom=this.clientHeight-50-this.itemHeight-this.gapWidth
? ? ? ? ? ? ? ? ? ? ? ? console.log(bottom,this.top)
? ? ? ? ? ? ? ? ? ? ? ? if(this.top>=bottom)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? this.top=bottom
? ? ? ? ? ? ? ? ? ? ? ? }
?
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? });
? ? ? ? ? ? });
? ? ? ? },
?
? ? ? ? methods:{
? ? ? ? ? ? onBtnClicked(){
? ? ? ? ? ? ? ? this.$emit("onFloatBtnClicked");
? ? ? ? ? ? },
?
? ? ? ? },
? ? ? ? data(){
? ? ? ? ? ? return{
? ? ? ? ? ? ? ? timer:null,
? ? ? ? ? ? ? ? currentTop:0,
? ? ? ? ? ? ? ? clientWidth:0,
? ? ? ? ? ? ? ? clientHeight:0,
? ? ? ? ? ? ? ? left:0,
? ? ? ? ? ? ? ? top:0,
? ? ? ? ? ? }
? ? ? ? }
? ? }
</script>
?
<style lang="scss" scoped>
? ? .ys-float-btn{
? ? ? ? background:rgba(56,181,77,1);
? ? ? ? box-shadow:0 2px 10px 0 rgba(0,0,0,0.1);
? ? ? ? border-radius:50%;
? ? ? ? color: #666666;
? ? ? ? z-index: 20;
? ? ? ? transition: all 0.3s;
? ? ? ? display: flex;
? ? ? ? flex-direction: column;
? ? ? ? justify-content: center;
? ? ? ? align-items: center;
? ? ? ? position: fixed;
? ? ? ? bottom: 20vw;
?
? ? ? ? img{
? ? ? ? ? ? width: 50%;
? ? ? ? ? ? height: 50%;
? ? ? ? ? ? object-fit: contain;
? ? ? ? ? ? margin-bottom: 3px;
? ? ? ? }
? ? }
? ? .su_img{
? ? ? ? width: 40px;
? ? ? ? height: 40px;
? ? ? ? margin: 8px 0 0 0;
? ? }
?
</style>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

焦作市| 乌苏市| 宜宾市| 谢通门县| 岚皋县| 交城县| 河津市| 正定县| 诸城市| 湘潭县| 湖南省| 东台市| 昌都县| 雅江县| 广元市| 吉林省| 县级市| 石城县| 武清区| 裕民县| 青浦区| 卢龙县| 赤水市| 金坛市| 呼伦贝尔市| 荣昌县| 鸡泽县| 邹城市| 呈贡县| 阿鲁科尔沁旗| 拜城县| 类乌齐县| 科技| 曲麻莱县| 阿克苏市| 桐乡市| 濮阳县| 莱西市| 万荣县| 柘荣县| 象州县|