简体   繁体   English

jQuery滑块/轮播计算

[英]JQuery Slider/Carousel Calculation

Basically I have a bottom bar that stores a definitive amount of objects, say 30, with a width of say 2000em. 基本上,我有一个底部栏,用于存储一定数量的对象(例如30个),宽度为2000em。

Now I want to make this div scrollable but every tutorial I look at does not explain their calculation. 现在,我想使该div可滚动,但是我看的每个教程都不能解释它们的计算。

My scroller will be unique because I will only allow scrolling via a next and back button (basically like paging) and I need to calculate when the div has 0 space to move so I can AJAX load more items and of course this calculation needs to be resize safe (based on div width and not pre-defined numbers). 我的滚动条将是唯一的,因为我将只允许通过next和back按钮滚动(基本上像分页一样),并且我需要计算div有0的移动空间,以便我可以AJAX加载更多的项目,当然,此计算需要调整安全大小(基于div宽度而不是预定义的数字)。

Now I am fine with the whole resize (recalc div width on resize event) and AJAX load more objects. 现在,我对整个调整大小(在调整大小事件上重新计算div宽度)都满意,并且AJAX加载了更多对象。

What I'm not fine with is the calculation required to understand how the div should scroll and how to judge when it has no more space to scroll. 我不满意的是需要理解div应该如何滚动以及如何判断何时没有更多滚动空间所需的计算。

Has anyone got experience with making a dynamic scroller that only acts uopn click of a next or previous button that could explain the calculation required to understand scrollLeft/Right? 有没有人有过制作动态滚动条的经验,该滚动条仅在单击下一个或上一个按钮时起作用,可以解释理解scrollLeft / Right所需的计算?

Thanks for any and all help, 感谢您的所有帮助,

I actually sorted this by: 我实际上按以下方式排序:

  1. Taking the current scrollLeft() of the inner ul within the div wrapper and add on the div (wrapper) width. 在div包装器中获取内部ul的当前scrollLeft()并添加div(包装器)宽度。
  2. I checked whether the sum from point 1 was less than the UL width. 我检查了从点1开始的总和是否小于UL宽度。
  3. If so then scroll otherwise load new page if there is one. 如果是这样,则滚动,否则,如果有一页,则加载新页面。

Reverse for the previous button. 反转上一个按钮。

Since the wrapper has a width of 100% specified it will always be the size of the screen which means no resize function needed. 由于包装器的宽度为100%,因此它将始终是屏幕的大小,这意味着不需要调整大小功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM