Vue横向滚动
P粉755863750
P粉755863750 2024-03-25 21:06:27
[Vue.js讨论组]

我想用鼠标水平滚动图标。我在Javascript中用scrollLeft尝试过,但滚动时该值不会改变。滚动时,只有 deltaY 值在 100 和 -100 之间变化。

有人知道问题出在哪里吗?

当我滚动并且鼠标悬停在滚动条上时,它可以工作,但我希望它可以在整个 div 容器上工作。如果可能的话,我也想在没有依赖项/npm-libraries 的情况下执行此操作。

模板

Javascript

import {
    FilterIcon
} from '@/components/Elements/'

export default {
    components: {
        FilterIcon,
    },
    computed: {
        rooms() {
            return this.$store.state.rooms
        }

    },
    methods: {
        ScrollIcons(event) {
            event.preventDefault()
            event.target.scrollLeft += event.deltaY
            console.log([event.deltaY, event.target.scrollLeft])
        }
    }
}

萨斯

.icons
    background: $bg
    width: 80%
    padding: 0.5rem 0.5rem
    ::-webkit-scrollbar
        width: $scrollbarSize
        height: 0.3rem
        background: $bg-glow
        border-radius: $radius_1
    ::-webkit-scrollbar-thumb
        background: $purple
        border-radius: $radius_1
    .instIconContainer
        width: 70%
        max-width: calc(40px * 4)
        max-height: 80px
        overflow-x: auto
        .instIcon
            width: $IconSize
            height: $IconSize
            min-width: $IconSize
            min-height: $IconSize
            path, circle
                fill: $purple

向下滚动时的控制台输出

[100, 0]

这就是它的样子

P粉755863750
P粉755863750

全部回复(1)
P粉434996845

我尝试了与您类似的方法,但直到我在 event.target.scrollLeft += event.deltaY 中使用 currentTarget 而不是 target 时才起作用 在您的 ScrollIcons 方法中。这样,当您在光标悬停在图标上时使用鼠标滚轮时,您将定位到包含的 div 或标签,而不是定位到图标。换句话说,只要您的光标位于包含的 div 和鼠标滚轮中,该 div 就应该做出响应,而不管 div 和鼠标光标之间的任何其他元素如何。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号