在最后<李>
Stop scroll on the end of the last <li>
我有这把小提琴http://jsfiddle.net/kureiii/45Exw/
var cur = 1;
var max = $(".collectionsCnt2").children("li").length;
$(".button-right").click(function () {
if (cur + 1 > max) return;
cur++;
$(".collectionsCnt2").animate({
marginLeft: "-=500px",
}, 1000);
});
(".button-left").click(function () {
if (cur - 1 < 1) return;
cur--;
$(".collectionsCnt2").animate({
marginLeft: "+=500px",
}, 1000);
});
滚动正在工作,但我希望滚动到最后一个li或最后一个框时停止?。。
试试这个:
var cur = 1;
var max = $(".collectionsCnt2").children("li").length;
$(".button-right").click(function () {
if (cur >= max) return;
cur = cur + (500/100 < max ? 500/100 : max);
$(".collectionsCnt2").animate({
marginLeft: "-=500px",
}, 1000);
});
$(".button-left").click(function () {
if (cur <= 1) return;
cur = cur - (500/100 < max ? 500/100 : max);
$(".collectionsCnt2").animate({
marginLeft: "+=500px",
}, 1000);
});
});
Fiddle
你可以这样做,而不是对值进行硬编码,
marginLeft: -$(".collectionsCnt2 li:last-child").offset().left + $(".collectionsCnt2")[0].scrollLeft -51 + 'px'
相关文章:
- 正在检测导航到<a name=“;最新主题”></a>
- 如何附加<ul><李>元素位于某个特定条件的父元素列表之间
- 在<script src=“"></脚本>标签
- 等效于<script src=“;something1.json”></脚本>
- CSS/.JS问题,<ul><李>在Megamenu中
- 如何在<td></td>在Procractor中
- 显示“<script src='some.js'></脚本>"在Html文档中
- 如何将Array转换为<ul><李>以字母为标题的字母列表
- <script src=“//代码.jquery.com/jquery-1.11.1.min.js”></
- 选择<脚本></脚本>作为html正文中的纯文本
- 可折叠<UL><李>不起作用
- $.mobile.loadPage()和$(“linkBtn”).click();t负载<头部></头部&
- <脚本/>vs<脚本></脚本>webpack和angular
- Javascript/RRails-如何包装link_to而不是<a></a>在javascript
- jQuery在处理<选择><选项>
- 布局lt md已被弃用.请使用`layout gt-<xxx>`变种
- 在<%%中定义的访问变量>从<脚本></脚本>
- 页面设计<a href><按钮><输入>在JSP中
- 注入html标记<ul></ul>在我的<李></李>元素
- jQuery选择器<按钮></按钮>