如何解决如何知道是否没有更多图片可以禁用nxt / prv按钮
| 我有这个代码 CSS:div#container{
overflow: hidden;
width: 331px;
}
div#content {
position:relative;
}
jQuery的:
$(\"#left\").click(function(){
$(\"#content\").animate({\"right\": \"+=328px\"},\"slow\");
});
$(\"#right\").click(function(){
$(\"#content\").animate({\"right\": \"-=328px\"},\"slow\");
});
HTML:
<button id=\"left\"><<</button>
<button id=\"right\">>></button>
<div id=\"container\">
<div id=\"content\">
<table border=\"0\">
<tr>
<td><img src=\"images/img1.gif\"></td>
<td><img src=\"images/img2.gif\"></td>
<td><img src=\"images/img3.gif\"></td>
<td><img src=\"images/img4.gif\"></td>
</tr>
<tr>
<td>Description1</td>
<td>Description2</td>
<td>Description3</td>
<td>Description4</td>
</tr>
</table>
当我单击例如prv按钮15次时,div每次移动328px!
我的问题是如何知道画廊应该停止活动的最后一个位置?
谢谢
解决方法
我不喜欢这样使用表格... Divs使您的代码更加流畅,并允许使用一个优雅的解决方案:is(\':: last-child \')on active div
但是由于您正在使用表格进行操作,因此我可以想到两种方法
一种是使用计数器,然后对照表的列数对其进行检查。如果每步显示多于一列,则它将是列/可见列的总数:
$(function(){
var position = 1;
$(\"#left\").click(function(){
var size = $(\"#content table\").find(\'tr\').first().find(\'td\').size();
if(position < (size / 2) ) {
$(\"#content\").animate({\"right\": \"+=198px\"},\"slow\");
position ++;
}
});
$(\"#right\").click(function(){
if( position > 1) {
$(\"#content\").animate({\"right\": \"-=198px\"},\"slow\");
position --;
}
});
});
小提琴:http://jsfiddle.net/9sYWK/5/
另一个解决方案是计算#content移动了多少次。您可以使用$(\"#content\").css(\'right\');
获得它。由于您知道自己始终以328px的步长移动div,因此可以将其除以328以得到点击次数
, 我不知道,您需要某种方式的柜台。
一种方法是连续计算td \?
//Add a class to your td\'s
<td class=\"img_gallery\"><img src=\"images/img1.gif\"></td>
<td class=\"img_gallery\"><img src=\"images/img2.gif\"></td>
<td class=\"img_gallery\"><img src=\"images/img3.gif\"></td>
<td class=\"img_gallery\"><img src=\"images/img4.gif\"></td>
// in your js ...
$td_count = $(\".img_gallery\").size();
// Now you have many different ways of dealing with this,// you can have a counter,or allow to move 5 * 328,whatever you want.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。