nickdekruijk/horizontal-scroller 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nickdekruijk/horizontal-scroller

最新稳定版本:3.0.2

Composer 安装命令:

composer require nickdekruijk/horizontal-scroller

包简介

Add a horizontal scrolling element

README 文档

README

Make a horizontal scrolling html element better by making it draggable and adding left/right buttons.

Usage

First make an element that is already nativly scrolling horizontaly, for left/right buttons to position properly you might need to wrap it in a relative positioned element for example:

<div class="relative">
    <div class="horizontal-scroller">
        <ul class="items">
            <li class="item">Item A</li>
            <li class="item">Item B</li>
            <li class="item">Item C</li>
            <li class="item">Item D</li>
            <li class="item">Item E</li>
            <li class="item">Item F</li>
            <li class="item">Item G</li>
            <li class="item">Item H</li>
            <li class="item">Item I</li>
            <li class="item">Item J</li>
        </ul>
    </div>
</div>

css:

.relative {
    position: relative;
}
.horizontal-scroller {
    overflow-x: auto;
    overflow-y: hidden;
}
.items {
    list-style: none;
    padding: 0;
    display: flex;
    gap: 40px;
}
.item {
    flex: 0 0 200px;
    padding: 5%;
    background-color: #ddd;
}

Then make it better by adding this javascript (these options are the default so you could just skip them all if needed):

<script src="horizontal-scroller.js"></script>
<script>
    new HorizontalScroller({
        selector: ".horizontal-scroller",
        buttonRight: true,
        buttonLeft: true,
        draggable: true,
    });
</script>

This will add two buttons that you can style yourself, for example:

.horizontal-scroller-button {
    position: absolute;
    display: block;
    height: 50px;
    width: 50px;
    top: 50%;
    transform: translateY(-50%);
}
.horizontal-scroller-button-left {
    left: 0:
}
.horizontal-scroller-button-right {
    right: 0:
}

See demo.html for a full working demo.

统计信息

  • 总下载量: 51
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-28