vue中出现横向滚动条,默认滑动到最右侧进行内容展示

1.html

<div  ref="scrollRef" class="box">
 <!-- 由内容撑起滚动条 -->
</div>

2.css

.box{
    width: 100%;
    overflow-x: scroll;
    overflow-y: hidden;
    &::-webkit-scrollbar {
      display: none;
    }
}

3.js

//获取完数据后,执行
//判断内容小于一屏时:
//let width = this.$refs.scrollRef.clientWidth;
//判断内容超过一屏时:
let width = this.$refs.scrollRef.scrollWidth;
this.$refs.scrollRef.scrollTo(width,0);
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
可以通过监听滚动事件来判断滚动条是否到达最右边,然后通过编程方式来触发页面跳转。具体实现可以参考以下代码: 1. 在 template 添加一个 div 容器,并给它添加一个 ref: ```html <div ref="scrollContainer" class="scroll-container"> <!-- 省略内容 --> </div> ``` 2. 在 script 监听 scroll 事件,并计算滚动条是否到达最右边: ```javascript <script> import { defineComponent } from 'vue'; export default defineComponent({ mounted() { const container = this.$refs.scrollContainer; container.addEventListener('scroll', this.handleScroll); }, methods: { handleScroll(event) { const container = event.target; const scrollWidth = container.scrollWidth; // 容器的滚动宽度 const scrollLeft = container.scrollLeft; // 滚动条的左侧距离容器左侧的距离 const clientWidth = container.clientWidth; // 容器的可见宽度 if (scrollWidth - scrollLeft === clientWidth) { // 滚动条到达最右侧 this.jumpToDetailPage(); } }, jumpToDetailPage() { // 实现跳转到详情页的逻辑 }, }, }); </script> ``` 3. 在 jumpToDetailPage 方法实现跳转到详情页的逻辑,具体实现可以根据你的具体需求来编写,例如: ```javascript jumpToDetailPage() { // 获取当前路由信息 const currentRoute = this.$router.currentRoute.value; // 构造跳转的路由信息 const detailRoute = { name: 'DetailPage', params: { id: currentRoute.params.id, }, }; // 调用路由的 push 方法进行跳转 this.$router.push(detailRoute); }, ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值