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

菲律宾bc网站总代理怎么做百度首页优化

菲律宾bc网站总代理怎么做,百度首页优化,centos yum wordpress,网站怎么去维护功能说明 ​​拖动功能​​: 鼠标按下时记录初始位置和滚动位置拖动过程中计算移动距离并更新滚动位置松开鼠标后根据速度实现惯性滚动 ​​滚动控制​​: 支持鼠标滚轮横向滚动(通过 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/266996.html

相关文章:

  • 做算法题的网站百度上怎么做推广
  • 台州企业网站制作公司网站推广策划书
  • 江门网站优化排名丹东seo推广优化报价
  • 亚马逊一个月赚5万难吗win优化大师有用吗
  • 做网站哪些公司百度云app下载安装
  • 加快政府网站建设的意见谷歌独立站推广
  • 互联网营销有哪些方式外包seo服务口碑好
  • 网站备案如何取消接入网络营销常见术语
  • 仿快法务网站开发模板常见的网络营销方式
  • 政府网站建设方案书怎么写大数据培训
  • 社会团体网站备案十堰seo优化
  • asp网站设计代做seo排名大概多少钱
  • 外贸网站设计制作河北seo诊断培训
  • 网站的系统帮助百度seo标题优化软件
  • 设计师在线网站免费建站软件
  • 建网站多少钱建个网站需要怎么做电商软文范例100字
  • 电脑网页制作软件有哪些何鹏seo
  • 网站建设及维护合同网站设计的基本原则
  • WordPress用云数据库seo人员培训
  • 做一个棋牌网站要多少钱企业管理软件
  • wordpress 参数传人网站seo标题是什么意思
  • 德州网站制作公司磁力搜索引擎
  • 网址大全下载到桌面上长沙seo霜天博客
  • 做贸易的都有什么网站cnzz
  • 网站建设方案书编写软件开发流程
  • 下载了模板如何做网站服务器域名查询
  • 彩票网站建设方案上海推广服务
  • 动漫建模代做网站百度一下百度公司推广电话
  • 高唐网站建设服务商百度人工投诉电话是多少
  • 盘龙城做网站武汉网站运营专业乐云seo