承接 nickdekruijk/horizontal-scroller 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nickdekruijk/horizontal-scroller

Composer 安装命令:

composer require nickdekruijk/horizontal-scroller

包简介

Add a horizontal scrolling element

README 文档

README

Make a natively horizontal-scrolling element better: drag it with the mouse, add prev/next buttons, and (optionally) play nicely with CSS scroll-snap.

Usage

Start with an element that already scrolls horizontally. For the prev/next buttons to position correctly, wrap it in a relatively positioned element:

<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>
            <!-- … -->
        </ul>
    </div>
</div>
.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 enhance it:

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

Options

All options are optional; the values below are the defaults.

Option Default Description
selector ".horizontal-scroller" Elements to enhance.
draggable true Drag the element horizontally with the mouse. While draggable, text selection inside the element is disabled (a drag surface, not prose).
buttonLeft true Insert a prev button.
buttonRight true Insert a next button.
buttonClass "horizontal-scroller-button" Base class for the injected buttons.
disableSnapOnDrag true Turn CSS scroll-snap off (inline) while dragging with the mouse and back on for button navigation, so a free drag doesn't snap back mid-drag. No-op if you don't use scroll-snap. Touch swipe and wheel are untouched.
infinite false Loop the items by cloning them (disabled automatically when the content isn't wide enough to scroll).

Buttons

The prev/next buttons are injected as empty elements right after the scroller, so you style them yourself. They get the base class plus a -left / -right modifier, and a hide class when the scroller reaches that edge (so you can fade/hide them):

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

Scroll-snap

Snap works out of the box — just declare it in CSS. With disableSnapOnDrag (on by default) a free mouse drag temporarily turns it off so it doesn't fight the drag, while the prev/next buttons scroll to an exact item and keep snap on:

.horizontal-scroller {
    scroll-snap-type: x mandatory;
}
.item {
    scroll-snap-align: start;
}

Optional: a thin scrollbar

A hairline scrollbar drawn inside a taller, easier-to-grab track, using WebKit's ::-webkit-scrollbar pseudo-elements. The gradients paint a 1px line for the track and a slightly thicker line for the thumb (swap #1f7a4d for your accent colour):

.horizontal-scroller::-webkit-scrollbar {
    height: 13px;
}
.horizontal-scroller::-webkit-scrollbar-track {
    background: linear-gradient(transparent, transparent 6px, #1f7a4d 6px, #1f7a4d 7px, transparent 7px);
}
.horizontal-scroller::-webkit-scrollbar-thumb {
    background: linear-gradient(transparent, transparent 2px, #1f7a4d 2px, #1f7a4d 11px, transparent 11px);
}
.horizontal-scroller::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(transparent, transparent 2px, #000 2px, #000 11px, transparent 11px);
}

Note: WebKit (Chrome/Safari) only. Do not also set the standard scrollbar-width or scrollbar-color — Chrome ignores every ::-webkit-scrollbar-* rule the moment either is present, and you'd lose the hairline. Firefox falls back to its default scrollbar.

Dragging

While dragging, the element gets a dragging class (e.g. to switch the cursor to grabbing). See demo.html for a full working demo.

nickdekruijk/horizontal-scroller 适用场景与选型建议

nickdekruijk/horizontal-scroller 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 73 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「javascript」 「scroll」 「scrollbar」 「horizontal」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nickdekruijk/horizontal-scroller 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nickdekruijk/horizontal-scroller 我们能提供哪些服务?
定制开发 / 二次开发

基于 nickdekruijk/horizontal-scroller 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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