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

java web网站开发结果凤凰网台湾资讯

java web网站开发结果,凤凰网台湾资讯,wordpress 用户导入,宣传 网站建设和政务公开代码实现了一个基本的滑动功能,通过鼠标按下、鼠标松开和鼠标移动事件来监听滑动操作。 具体实现逻辑如下: 在 onMounted 钩子函数中,我们为滚动容器添加了三个事件监听器:mousedown 事件:当鼠标按下时,设置…

代码实现了一个基本的滑动功能,通过鼠标按下、鼠标松开和鼠标移动事件来监听滑动操作。

具体实现逻辑如下:

  • 在 onMounted 钩子函数中,我们为滚动容器添加了三个事件监听器:
  • mousedown 事件:当鼠标按下时,设置 control.isDown 为 true,记录鼠标起始位置 control.startX 和滚动条位置 control.scrollLeft
  • mouseup 事件:当鼠标松开时,设置 control.isDown 为 false,表示鼠标已经抬起。
  • mousemove 事件:当鼠标移动时,如果 control.isDown 为 true,则计算鼠标的滑动距离 walk,并将滚动容器的 scrollLeft 属性设置为 control.scrollLeft - walk

通过这些事件监听,我们可以实现鼠标滑动时滚动容器的滚动效果。

另外,该代码还包括了点击左右箭头按钮时的滑动功能。在 onPageLeft 方法中,通过修改滚动容器的 scrollLeft 属性,实现向左滑动一个容器宽度的距离;在 onPageRight 方法中,通过修改滚动容器的 scrollLeft 属性,实现向右滑动一个容器宽度的距离。

结构代码

<template><div class="swiper"><div class="watch-list-arrow watch-list-arrow--left" @click="onPageLeft"><div class="watch-list-arrow-btn">←</div></div><div ref="currencyItemsRef" class="currency-items"><div class="currency-item" v-for="(item, index) in symbols" :key="index">{{ item }}</div></div><div class="watch-list-arrow watch-list-arrow--right" @click="onPageRight"><div class="watch-list-arrow-btn">→</div></div></div>
</template>

业务逻辑

<script setup>
import { ref, reactive, onMounted } from 'vue';
const symbols = ref(['BTC111','ETH','XRP','LTC','BCH','ADA','DOGE','DOT','LINK','UNI1','UNI2','UNI3','UNI4','UNI5','UNI6','UNI999'
]);const currencyItemsRef = ref(null);// 左右箭头滑动
const onPageLeft = () => {// 版本一// currencyItemsRef.value.scrollLeft -= currencyItemsRef.value.offsetWidth;// 版本二//   const containerWidth = currencyItemsRef.value.clientWidth;//   const currentScrollLeft = currencyItemsRef.value.scrollLeft;//   const nextScrollLeft = currentScrollLeft - containerWidth;//   if (nextScrollLeft >= 0) {//     currencyItemsRef.value.scrollTo({//       left: nextScrollLeft,//       behavior: 'smooth'//     });//   } else {//     currencyItemsRef.value.scrollTo({//       left: 0,//       behavior: 'smooth'//     });//   }//  版本三currencyItemsRef.value.scroll({left:currencyItemsRef.value.scrollLeft - currencyItemsRef.value.offsetWidth,behavior: 'smooth'});
};const onPageRight = () => {// 版本一// currencyItemsRef.value.scrollLeft += currencyItemsRef.value.offsetWidth;// 版本二//   const containerWidth = currencyItemsRef.value.clientWidth;//   const maxScrollLeft = currencyItemsRef.value.scrollWidth - containerWidth;//   const currentScrollLeft = currencyItemsRef.value.scrollLeft;//   const nextScrollLeft = currentScrollLeft + containerWidth;//   if (nextScrollLeft <= maxScrollLeft) {//     currencyItemsRef.value.scrollTo({//       left: nextScrollLeft,//       behavior: 'smooth'//     });//   } else {//     currencyItemsRef.value.scrollTo({//       left: maxScrollLeft,//       behavior: 'smooth'//     });//   }// 版本三currencyItemsRef.value.scroll({left:currencyItemsRef.value.scrollLeft + currencyItemsRef.value.offsetWidth,behavior: 'smooth'});
};// 鼠标滑动
const control = reactive({isDown: false, // 是否按下鼠标startX: 0, // 鼠标起始位置scrollLeft: 0 // 滚动条位置
});const move = (e) => {if (!control.isDown) return;e.preventDefault();const x = e.pageX - currencyItemsRef.value.offsetLeft;const walk = (x - control.startX) * 2; // 滑动距离currencyItemsRef.value.scrollLeft = control.scrollLeft - walk;//   control.scrollLeft = control.scrollLeft - walk;//   requestAnimationFrame(() => {//     currencyItemsRef.value.scrollLeft = control.scrollLeft;//   });
};onMounted(() => {console.log('dom', currencyItemsRef.value);// 总结web端实现滑动,就是对鼠标按下、鼠标松开、鼠标移动事件进行监听currencyItemsRef.value.addEventListener('mousedown', (e) => {control.isDown = true;control.startX = e.pageX - currencyItemsRef.value.offsetLeft;control.scrollLeft = currencyItemsRef.value.scrollLeft;});currencyItemsRef.value.addEventListener('mouseup', (e) => {control.isDown = false;});currencyItemsRef.value.addEventListener('mousemove', move);
});
</script>
<!-- 在这个示例中,我们使用 vue 的 ref 函数创建了 currencyItemsRef 引用,它指向滚动容器的 div 元素。我们还定义了 onPageLeft 和 onPageRight 方法,用于处理点击左右箭头时的滑动事件。在 onPageLeft 方法中,我们通过减去滚动容器的宽度,实现了向左滑动一个容器宽度的距离。同样地,在 onPageRight 方法中,我们通过加上滚动容器的宽度,实现了向右滑动一个容器宽度的距离。通过点击左右箭头按钮,你可以看到滚动容器会相应地滑动,展示出不同的项目。-->

 样式

<style lang="scss" scoped>
.swiper {display: flex;align-items: center;width: 800px;overflow: hidden;
}.watch-list-arrow {display: flex;align-items: center;justify-content: center;width: 30px;height: 30px;background-color: lightgray;cursor: pointer;
}.watch-list-arrow-btn {width: 100%;height: 100%;display: flex;align-items: center;justify-content: center;font-size: 20px;
}.currency-items {display: flex;gap: 10px;overflow-x: scroll;scroll-behavior: smooth;scroll-snap-type: x mandatory;-webkit-overflow-scrolling: touch;/* &::-webkit-scrollbar {display: none;} */
}.currency-item {flex: 0 0 auto;width: 100px;height: 100px;background-color: lightblue;
}
</style>

http://www.wooajung.com/news/30129.html

相关文章:

  • pptseo教程搜索引擎优化
  • 衡水网站制作公司哪家专业防疫管控优化措施
  • 如何搜索易思cms做的网站百度快照
  • 百度网站怎么做的赚钱吗百度seo按天计费
  • 做网站都有备案吗网络推广主要工作内容
  • wordpress自助友链汕头seo公司
  • 杭州网站建设及推广网站seo快速排名优化的软件
  • 高端网站建设企业官网建设seochinaz查询
  • 微信获客crm平台广东网站优化公司
  • ps做网站显示内容参考宁波企业网站seo
  • 西安seo盐城海外aso优化
  • 上海市建设工程安全质量监督总站网站广告资源网
  • 域名解析网站建设厦门人才网官网招聘信息网
  • 没备案的网站怎么做淘客海外营销
  • 建设厅职业资格中心网站揭阳seo快速排名
  • 上门做网站哪里有google搜索入口
  • 广州市提取住房补贴建设银行网站seo基础
  • 企业网站建设套餐黄页网站推广
  • 李沧做网站公司关于进一步优化 广州
  • 网站套利怎么做seo优化服务价格
  • 企业网站制作需要多少费用互联网推广渠道
  • 视频网站开发难点百度一下首页网页百度
  • 免费的图库网站百度客户服务电话是多少
  • 网站主页和子页怎么做莆田百度seo公司
  • wordpress5.2seo有名气的优化公司
  • 用七牛做网站东莞谷歌推广公司
  • 个人网站域名后缀免费推广的app有哪些
  • 网站建设与网页设计ppt媒体公关是做什么的
  • app store下载官方搜索引擎seo是什么
  • 做团购网站需要什么资质怎么做seo信息优化