技术标签: vue3.x开发实例 vue3美化滚动条 Vue.js自定义组件 vue3.0自定义滚动条 vue3自定义组件 vue3.x模拟滚动条 vue3虚拟滚动条
一款基于vue3.x构建的pc端自定义模拟滚动条|vue3.0美化滚动条组件。支持监听DOM尺寸变化、是否原生滚动、是否自动隐藏滚动条、自定义尺寸/颜色及层级等功能。
import { createApp } from 'vue'
import App from './App.vue'
import './index.css'
// 引入滚动条组件v3scroll
import V3Scroll from './components/v3scroll'
createApp(App).use(V3Scroll).mount('#app')
<!-- //自定义参数 -->
<v3-scroll size="10" color="#ff5588" zIndex="1000">
<p>显示自定义内容!</p>
</v3-scroll>
<!-- //scroll事件处理 -->
<v3-scroll @scroll="handleScroll">
<p>显示自定义内容!</p>
</v3-scroll>
效果和饿了么滚动条组件有些类似。并且支持监听DOM尺寸改变,动态更新滚动条。
v3scroll支持如下参数自定义配置。
props: {
// 是否显示原生滚动条
native: Boolean,
// 是否自动隐藏滚动条
autohide: Boolean,
// 滚动条尺寸
size: { type: [Number, String], default: '' },
// 滚动条颜色
color: String,
// 滚动条层级
zIndex: null
},
组件模板
<template>
<div class="vui__scrollbar" ref="ref__box" @mouseenter="handleMouseEnter" @mouseleave="handleMouseLeave" v-resize="handleResize">
<div :class="['vscroll__wrap', {native: native}]" ref="ref__wrap" @scroll="handleScroll">
<div class="vscroll__view" v-resize="handleResize">
<slot />
</div>
</div>
<div :class="['vscroll__bar vertical']" @mousedown="handleClickTrack($event, 0)" :style="{'width': parseInt(size)>=0 ? parseInt(size)+'px' : '', 'z-index': parseInt(zIndex)>=0 ? parseInt(zIndex) : ''}">
<div class="vscroll__thumb" ref="ref__barY" :style="{'background': color, 'height': barHeight+'px'}" @mousedown="handleDragThumb($event, 0)"></div>
</div>
<div :class="['vscroll__bar horizontal']" @mousedown="handleClickTrack($event, 1)" :style="{'height': parseInt(size)>=0 ? parseInt(size)+'px' : '', 'z-index': parseInt(zIndex)>=0 ? parseInt(zIndex) : ''}">
<div class="vscroll__thumb" ref="ref__barX" :style="{'background': color, 'width': barWidth+'px'}" @mousedown="handleDragThumb($event, 1)"></div>
</div>
</div>
</template>
vue2.x和vue3中使用自定义指令有些不一样。
// vue 2
const MyDirective = {
bind(el, binding, vnode, prevVnode) {},
inserted() {},
update() {},
componentUpdated() {},
unbind() {}
}
// vue 3
const MyDirective = {
beforeMount(el, binding, vnode, prevVnode) {},
mounted() {},
beforeUpdate() {},
updated() {},
beforeUnmount() {},
unmounted() {}
}
v3scroll核心逻辑处理。
/**
* @Desc Vue3.0虚拟滚动条组件V3Scroll
* @Time andy by 2021-01
* @About Q:282310962 wx:xy190310
*/
<script>
import { onMounted, ref, reactive, toRefs, nextTick } from 'vue'
import domUtils from './utils/dom'
export default {
props: {
// ...
},
/**
* Vue3.x自定义指令写法
*/
// 监听DOM尺寸变化
directives: {
'resize': {
beforeMount: function(el, binding) {
let width = '', height = '';
function get() {
const elStyle = el.currentStyle ? el.currentStyle : document.defaultView.getComputedStyle(el, null);
if (width !== elStyle.width || height !== elStyle.height) {
binding.value({width, height});
}
width = elStyle.width;
height = elStyle.height;
}
el.__vueReize__ = setInterval(get, 16);
},
unmounted: function(el) {
clearInterval(el.__vueReize__);
}
}
},
setup(props, context) {
const ref__box = ref(null)
const ref__wrap = ref(null)
const ref__barX = ref(null)
const ref__barY = ref(null)
const data = reactive({
barWidth: 0, // 滚动条宽度
barHeight: 0, // 滚动条高度
ratioX: 1, // 滚动条水平偏移率
ratioY: 1, // 滚动条垂直偏移率
isTaped: false, // 鼠标光标是否按住滚动条
isHover: false, // 鼠标光标是否悬停在滚动区
isShow: !props.autohide, // 是否显示滚动条
})
onMounted(() => {
nextTick(() => {
updated()
})
})
// 鼠标滑入
const handleMouseEnter = () => {
data.isHover = true
data.isShow = true
updated()
}
// 鼠标滑出
const handleMouseLeave = () => {
data.isHover = false
data.isShow = false
}
// 拖动滚动条
const handleDragThumb = (e, index) => {
const elWrap = ref__wrap.value
const elBarX = ref__barX.value
const elBarY = ref__barY.value
data.isTaped = true
let c = {}
// 阻止默认事件
domUtils.isIE() ? (e.returnValue = false, e.cancelBubble = true) : (e.stopPropagation(), e.preventDefault())
document.onselectstart = () => false
if(index == 0) {
c.dragY = true
c.clientY = e.clientY
}else {
c.dragX = true
c.clientX = e.clientX
}
// ...
}
// 点击滚动槽
const handleClickTrack = (e, index) => {
// ...
}
// 更新滚动区
const updated = () => {
if(props.native) return
const elBox = ref__box.value
const elWrap = ref__wrap.value
const elBarX = ref__barX.value
const elBarY = ref__barY.value
let barSize = domUtils.getScrollBarSize()
// 垂直滚动条
if(elWrap.scrollHeight > elWrap.offsetHeight) {
data.barHeight = elBox.offsetHeight **2 / elWrap.scrollHeight
data.ratioY = (elWrap.scrollHeight - elBox.offsetHeight) / (elBox.offsetHeight - data.barHeight)
elBarY.style.transform = `translateY(${elWrap.scrollTop / data.ratioY}px)`
// 隐藏系统滚动条
if(barSize) {
elWrap.style.marginRight = -barSize + 'px'
}
}else {
data.barHeight = 0
elBarY.style.transform = ''
elWrap.style.marginRight = ''
}
// 水平滚动条
// ...
}
// 滚动区元素/DOM尺寸改变
const handleResize = () => {
// 执行更新操作
}
// ...
return {
...toRefs(data),
ref__box, ref__wrap, ref__barX, ref__barY,
handleMouseEnter, handleMouseLeave,
handleDragThumb, handleClickTrack,
updated,
// ...
}
}
}
</script>
<v3-scroll @scroll="handleScroll">
<p><img src="https://cn.vuejs.org/images/logo.png" style="height:250px;" /></p>
<p>内容信息!这里是内容信息!这里是内容信息!这里是内容信息!这里是内容信息!</p>
</v3-scroll>
setup(){
// 监听滚动事件
handleScroll(e) {
this.scrollTop = e.target.scrollTop
// 判断滚动状态
if(e.target.scrollTop == 0) {
this.scrollStatus = '到达顶部'
} else if(e.target.scrollTop + e.target.offsetHeight >= e.target.scrollHeight) {
this.scrollStatus = '到达底部'
}else {
this.scrollStatus = '滚动中....'
}
}
// ...
}
Okay,基于vue3.x开发自定义滚动条组件就分享到这里。希望对大家有些帮助!
1、主要原因启动类和controller的位置关系不对。2、解决方法(1)官方推荐 保证 :启动类 和 Controller 有 共同的 父包 。如上图中的myproject。(2)增加@ComponentScan注解如果 启动类 和 controller 没有共同的父包,则需要在启动上增加@ComponentScan注解,具体见下图:假设源码的..._springboot controller扫描不到
title: Pipeline manipulation…Pipeline manipulationThis chapter presents many ways in which you can manipulate pipelines fromyour application. These are some of the topics that will be covered:How to insert data from an application into a pipelineHo._indexerror: there are no images in the pipeline. add a directory using add_d
什么是CI/CD?CI: 持续集成(Continuous integration),持续集成是指多名开发者在开发不同功能代码的过程当中,可以频繁的将代码行合并到一起并切相互不影响工作。是基于某种工具或平台实现代码自动化的构建、测试和部署到线上环境以实现交付高质量的产品,持续部署在某种程度上代表了一个开发团队的更新迭代速率。CD: 持续交付(Continuous Delivery),持续交付是持续集成的扩展,指的是将通过自动化测试的软件部署到产品环境。持续交付的本质是把每个构建成功的应用更新交付给用户使用_springcloud cicd
太久没写了,今天补一篇,本篇无实际代码,主要是设计思路。关于JWT:在我所开发的系统中用户Token都是有意义的,都会携带部分数据,不过多用于userId个人的权限系统使用历程:基于Security(不加表、角色放在Token中)注解验证(乱七八糟)使用Spring Security框架,将用户角色ROLE_USER写在account表中,UserDetailsService的实现方法中封装UserDetails返回,然后在接口上添加注解进行权限校验好处是简单,但是权限写在逻辑里面了。改权限就_接口权限设计
SticksTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 115807 Accepted: 26640DescriptionGeorge took sticks of the same length and cut them randomly until a
硬件环境 :MT7628ANOpenWRT中WAN和LAN的配置在 /etc/config/network 文件中,下面是目前自己使用的 network 文件内容,留个笔记以备后续使用。config interface 'loopback' option ifname 'lo' option proto 'static' option ipaddr '1..._openwrt编辑network
CPU占用情况如图,有哪位遇到过,帮我分析下什么情况
大部分技术公司在用git管理代码时,经常会要求commit信息的格式,格式不对是提不上去的。寻找并修改错误信息也是个技术活,我在这方面没少吃亏,现在就把自己的经验分享给大家:/修改历史提交信息 git rebase -i HEAD~3(这个数字3只是为了示例,你可以任意给)这个命令出来之后,会出来三行东东: pick:*******pick:******_git rebase head
许多win7系统用户在工作中经常需要对win7系统清理缓存为电脑提速进行设置,比如近日有用户到本站反映说win7系统清理缓存为电脑提速的问题,但是却不知道要怎么设置win7系统清理缓存为电脑提速,其实我们依照1、首先我们打开开始菜单,在菜单的搜索框中输入“磁盘”,然后在出现的列表中选择点击“磁盘清理”; 2、然后在弹出来的磁盘清理驱动器中,选择所需要清理的驱动器,这里选择“C盘”这样的步骤就可以了..._windows7清理加速
1,ESX 网络结构 1.1网络元素 esx网络元素包括 vmnic, vSwitch, VM Network, Service Console,vswif vmnic 对应物理主机的物理网卡,例如vmnic0 对应eth0 依次类推vSwitch 虚拟交换机,为虚拟出来的主机提供网络接口,相当于桥设备,用于连接客户机虚拟网卡和外部网络,可以多...
1. 原由由于不同系统的字符集设定会存在差异,导致在一个环境中开发的.NET Winform应用程序到另一个环境下变得显示不全或排列混乱2. 解决方法设置Form的属性AutoScaleMode 为None(默认为Font),设置Form的AutoSize属性为False(默认为False)另解:设置Form的AutoSize为True,AutoSizeMode为GrowO_winform怎么根据显示设置保持不变
sqlserver必须声明标量变量 "@id"。原因set @sql = 'insert into stu(id,name) select top @id from stus‘ // 错误 解决办法set @sql = 'insert into stu(id,name) select top '+CONVERT(char(3),@id) +'from stus‘ //_必须声明标量变量 "@id