如何实现高级的Javascript内容滑块?

发布于 2025-01-04 15:13:05 字数 330 浏览 3 评论 0原文

我是一名设计师,负责实现类似于以下模型的水平 JS 滑块(按向右和向左箭头按钮查看我的目标):

http://hovenftp.com/spinscroll/scroll1.html (可能需要一些时间来加载)

我已经做了很多谷歌搜索来找到一个可以调整以实现类似功能的库,但我没有运气。我的 JS 技能严重缺乏,所以我不知道从哪里开始构建它。我猜测涉及绝对定位和条件的东西可以处理蓝色选择器的移动,但专辑也需要左右滚动。

任何帮助或提示将不胜感激。

I'm a designer in charge of implementing a horizontal JS slider similar to the follow mockup (press the right and left arrow buttons to see what I'm aiming for):

http://hovenftp.com/spinscroll/scroll1.html
(it may take some time to load)

I've done a lot of Googling to find a library that I can tweak to achieve something similar, but I've had no luck. My JS skills are woefully lacking, so I'm not sure where to even get started on building it from scratch. I'm guessing something involving absolute positioning and conditionals could handle the movement of the blue selector, but the albums need to scroll left and right too.

Any help or tips would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

乖乖 2025-01-11 15:13:05

那么html结构是这样的;

div.viewport -> wrapping the whole slide and defining the 'viewport' of your slider
    div.slider -> this wraps all the single images and has a width of 900000px
        div.img -> this wraps the actual image and has a blue border on 'selected'
        div.img -> another
        div.img -> and another..

您的 javascript 会计算 div.img 并计算 div.slider 宽度。然后,您将始终检查活动的 div.img 是否在 div.viewport 内,如果不在,请设置 div.slider 的 left 或 margin-left 样式,以便其位于视口中。这就是我为我工作的新闻公司开发滑块的方式 (www.20min.ch)

well the html structure is like this;

div.viewport -> wrapping the whole slide and defining the 'viewport' of your slider
    div.slider -> this wraps all the single images and has a width of 900000px
        div.img -> this wraps the actual image and has a blue border on 'selected'
        div.img -> another
        div.img -> and another..

your javascript would count the div.img and calculate the div.slider width. You would then always check to see if the active div.img is within the div.viewport, if not, set the div.slider's left or margin-left style, so that its in the viewport. Thats how I've developed the sliders for the newscompany I work for (www.20min.ch)

赠佳期 2025-01-11 15:13:05

我喜欢使用 Cycle 来做这样的事情。轻量级、文档齐全且易于定制以满足您的需求。

I like using Cycle for stuff like this. Lightweight, well-documented and easy to customize to suit your needs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文