当前位置: 首页 > wzjs >正文

菲律宾bc网站总代理怎么做最新域名解析

菲律宾bc网站总代理怎么做,最新域名解析,网站怎么做登录,ppt网站有哪些功能说明 ​​拖动功能​​: 鼠标按下时记录初始位置和滚动位置拖动过程中计算移动距离并更新滚动位置松开鼠标后根据速度实现惯性滚动 ​​滚动控制​​: 支持鼠标滚轮横向滚动(通过 wheel 事件)自动边界检测防止滚动超出内容…

功能说明

​​拖动功能​​:

  • 鼠标按下时记录初始位置和滚动位置
  • 拖动过程中计算移动距离并更新滚动位置
  • 松开鼠标后根据速度实现惯性滚动

​​滚动控制​​:

  • 支持鼠标滚轮横向滚动(通过 wheel 事件)
  • 自动边界检测防止滚动超出内容范围

实现代码

<template><div ref="scrollContainer" class="horizontal-scroll-container"@mousedown="startDrag"@mousemove="onDrag"@mouseup="stopDrag"@mouseleave="stopDrag"><div class="scroll-content"><div v-for="(item, index) in items" :key="index" class="item">{{ item }}</div></div></div>
</template><script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'// 定义滚动容器引用
const scrollContainer = ref<HTMLElement | null>(null)// 定义滚动内容数据
const items = ref<string[]>(Array.from({ length: 20 }, (_, i) => `Item ${i + 1}`))// 拖动状态变量
let isDragging = false
let startX = 0
let scrollLeft = 0
let lastTime = 0
let velocity = 0// 开始拖动
const startDrag = (e: MouseEvent): void => {if (!scrollContainer.value) returnisDragging = truestartX = e.pageX - scrollContainer.value.getBoundingClientRect().leftscrollLeft = scrollContainer.value.scrollLeftlastTime = performance.now()scrollContainer.value.style.cursor = 'grabbing'
}// 拖动中
const onDrag = (e: MouseEvent): void => {if (!isDragging || !scrollContainer.value) returnconst x = e.pageX - scrollContainer.value.getBoundingClientRect().leftconst walk = (x - startX) * 1.5 // 调整滚动速度系数scrollContainer.value.scrollLeft = scrollLeft - walk// 计算速度(用于惯性滚动)const now = performance.now()velocity = (x - startX) / (now - lastTime)lastTime = now
}// 停止拖动
const stopDrag = (): void => {if (!isDragging || !scrollContainer.value) returnisDragging = falseif (Math.abs(velocity) > 0.1) {requestAnimationFrame(inertiaScroll)}scrollContainer.value.style.cursor = 'grab'
}// 惯性滚动
const inertiaScroll = (): void => {if (!scrollContainer.value || Math.abs(velocity) < 0.01) returnscrollContainer.value.scrollLeft += velocity * 10velocity *= 0.95 // 摩擦系数requestAnimationFrame(inertiaScroll)
}// 边界检测
const checkBounds = (): void => {if (!scrollContainer.value) returnconst containerWidth = scrollContainer.value.clientWidthconst contentWidth = scrollContainer.value.scrollWidthif (scrollContainer.value.scrollLeft < 0) {scrollContainer.value.scrollLeft = 0} else if (scrollContainer.value.scrollLeft > contentWidth - containerWidth) {scrollContainer.value.scrollLeft = contentWidth - containerWidth}
}// 鼠标滚轮横向滚动
const handleWheel = (e: WheelEvent): void => {if (!scrollContainer.value) returne.preventDefault()scrollContainer.value.scrollLeft += e.deltaYcheckBounds()
}// 生命周期钩子
onMounted(() => {if (scrollContainer.value) {scrollContainer.value.addEventListener('wheel', handleWheel, { passive: false })}
})onUnmounted(() => {if (scrollContainer.value) {scrollContainer.value.removeEventListener('wheel', handleWheel)}
})
</script><style scoped>
.horizontal-scroll-container {width: 100%;overflow-x: auto;white-space: nowrap;cursor: grab;height: 220px; /* 确保容器有固定高度 */border: 1px solid #eee;border-radius: 8px;padding: 10px;box-sizing: border-box;
}.horizontal-scroll-container:active {cursor: grabbing;
}.scroll-content {display: inline-block;
}.item {display: inline-block;width: 200px;height: 200px;margin-right: 10px;background: #f0f0f0;display: flex;align-items: center;justify-content: center;font-size: 20px;border: 1px solid #ddd;box-sizing: border-box;border-radius: 4px;transition: transform 0.2s ease, box-shadow 0.2s ease;
}.item:hover {transform: scale(1.02);box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
</style>
http://www.dtcms.com/wzjs/463349.html

相关文章:

  • 菏泽财富中心网站建设创建网站的软件
  • 保定市建设局质监站网站短网址
  • 宝宝投票网站怎么做的网络黄页推广大全
  • 前海网站建设优化设计答案四年级上册语文
  • 丽水做网站企业腾讯网qq网站
  • 上海财务代理记账外包铁岭网站seo
  • node怎么做网站热狗seo顾问
  • 石家庄网站制作北京seo分析
  • 房地产贷款最新政策自动优化app
  • 宜昌网站推广长春网站建设平台
  • 做网站就业要会什么新闻投稿
  • 网站快速过备案雏鸟app网站推广
  • 做机械的专业外贸网站有哪些代写文案平台
  • 花生壳 做网站网络整合营销方案
  • 全面的郑州网站建设国内前10电商代运营公司
  • 仙桃网站建设seo的概念是什么
  • 深圳网站建设设计搜狗seo怎么做
  • 湖北专业网站建设设计引流推广平台软件
  • 耒阳市人民政府门户网站有趣的网络营销案例
  • 设计logo网站侵权吗知乎百度推广信息流有用吗
  • 义乌外贸网站建设知乎关键词搜索排名
  • 网站独立店铺系统软文发稿系统
  • 网站设计方案公司推广之家app下载
  • 有移动端网站 怎么做app百度搜索指数排名
  • 做传奇网站报毒怎么处理苏州网站关键词优化推广
  • 动漫做a视频网站有哪些seo课程培训中心
  • 接私活做网站软文代发平台
  • 怎么用网吧电脑做网站服务器大型网站建设平台
  • 汽车类网站搭建百度seo招聘
  • 长沙手机网站设计公司今日重大财经新闻