【前端开发】可拉动宽度窗口

1. 组件:Resize

<template>
  <div :style="{width: defaultWidth + 'px', position: 'relative'}">
    <div ref="container" class="d-flex">
      <div style="width: 100%; height: 100vh;">
        <!--        显示内容主体-->
        <slot name="body"></slot>
      </div>
    </div>

    <!-- 拖拽条 -->
    <div v-if="resizeShow" class="resize" @mousedown.stop="onMouseDown" @mouseup.stop="onMouseup"/>
  </div>

</template>

<script>
export default {
  props: {
    // 控制拖拽条的是否显示,默认显示
    resizeShow: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      defaultWidth: 240,
      beforeWidth: 0,
      afterWidth: 0
    }
  },
  methods: {
    // 按下鼠标开始监听鼠标移动事件
    onMouseDown(e) {
      this.beforeWidth = e.clientX
      document.addEventListener('mousemove', this.onMousemove)
      document.addEventListener('mouseup', this.onMouseup)
      e.preventDefault()
    },

    // 监听鼠标移动 实现盒子宽度变化
    onMousemove(e) {
      this.afterWidth = e.clientX
      // 根据鼠标位置判断向左还是向右拖动
      if (this.beforeWidth < this.afterWidth) {
        this.defaultWidth = this.defaultWidth + (this.afterWidth - this.beforeWidth)
        this.beforeWidth = e.clientX
      } else {
        this.defaultWidth = this.defaultWidth - (this.beforeWidth - this.afterWidth)
        this.beforeWidth = e.clientX
      }
    },

    onMouseup(e) {
      e.preventDefault()
      // 松开鼠标后移除监听
      document.removeEventListener('mousedown', this.onMouseDown)
      document.removeEventListener('mousemove', this.onMousemove)
    }
  }
}

</script>

<style>
.d-flex {
  display: inline-block;
  overflow: hidden;
  width: 100%;
}

.resize {
  position: absolute;
  top: 0;
  right: 1px;
  display: inline-block;
  width: 20px;
  height: 100%;
  cursor: col-resize;
  margin: 0 1px;
}
</style>

2. JavaScript调用组件

<template>
  <div class="app-box">
    <ResizeBox :resizeShow="resizeShow"/>
  </div>
</template>
<script>
import ResizeBox from './components/ResizeBox/index.vue';
export default {
  data(){
    return{
      resizeShow:true  //是否可拖动修改宽度
    }
  },
  components:{
    ResizeBox
  }
}
</script>
<style scoped>
.app-box {
  display: flex;
}
</style>

3. TypeScript调用组件

<template>
  <div class="app-box">
    <ResizeBox :resizeShow="resizeShow"/>
  </div>
</template>
<script setup lang="ts">
import ResizeBox from './components/ResizeBox/index.vue';

//是否可拖动改变宽度
let resizeShow = true;  
</script>
<style scoped>
.app-box {
  display: flex;
}
</style>

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Fuchsia是Google开发的一种新型操作系统,其前端开发涉及到开发用户界面(UI)以及用户体验(UX)。Fuchsia前端开发主要包括以下几个方面: 首先,Fuchsia前端开发需要熟悉Fuchsia操作系统的架构和设计理念。Fuchsia采用了微内核架构,前端开发者需要了解Fuchsia的组件和服务间的通信机制,以及如何使用Fuchsia的API进行开发。 其次,Fuchsia前端开发需要掌握谷歌的开发工具和技术。例如,Flutter是谷歌推出的用于开发跨平台应用的工具,Fuchsia前端开发可以使用Flutter来开发Fuchsia应用的用户界面。前端开发者需要熟悉Flutter的语法和组件库,以及如何使用Flutter进行布局、动画和交互等方面的开发。 另外,Fuchsia前端开发还需要关注用户体验(UX)的设计。前端开发者需要了解如何设计符合Fuchsia用户界面准则的界面,以提供流畅、一致且美观的用户体验。这包括对界面元素的布局、颜色和字体等方面的设计。 最后,Fuchsia前端开发需要进行测试和调试。前端开发者需要学会使用调试工具来检查和修复应用中可能出现的问题,以确保应用的稳定性和性能。 总而言之,Fuchsia前端开发需要具备对Fuchsia操作系统的深入了解,掌握开发工具和技术,关注用户体验设计,并具备良好的测试和调试能力。只有熟练掌握这些要素,才能够开发出高质量的Fuchsia前端应用。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值