Jquery 如何知道是否没有更多要禁用的pics(nxt/prv)按钮

Jquery 如何知道是否没有更多要禁用的pics(nxt/prv)按钮,jquery,html,image,jquery-animate,Jquery,Html,Image,Jquery Animate,我有这个密码 css: jquery: $("#left").click(function(){ $("#content").animate({"right": "+=328px"}, "slow"); }); $("#right").click(function(){ $("#content").animate({"right": "-=328px"}, "slow"); }); HTML: 说明1 说明2 说明3 说明4 例如,当我点击prv按钮15次时,div每次移动328px!

我有这个密码

css:

jquery:

$("#left").click(function(){
$("#content").animate({"right": "+=328px"}, "slow");
});

$("#right").click(function(){
$("#content").animate({"right": "-=328px"}, "slow");
});
HTML:


说明1
说明2
说明3
说明4
例如,当我点击prv按钮15次时,div每次移动328px! 我的问题是如何知道画廊应该停止移动的最后一个位置


谢谢你

我不喜欢用桌子来做这个。。。div使代码更加流畅,并允许一个优雅的解决方案:活动div上的is(':last child')

但既然你们是用桌子做的,我可以想出两种方法

一种是使用计数器,然后对照表中的列数进行检查。如果每个步骤显示多个列,则为列/可见列的总数:

$(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 --;
        }
    });
});
$(函数(){
var位置=1;
$(“#左”)。单击(函数(){
变量大小=$(“#内容表”).find('tr').first().find('td').size();
如果(位置<(尺寸/2)){
$(“#content”).animate({“right”:“+=198px”},“slow”);
位置++;
}
});
$(“#右”)。单击(函数(){
如果(位置>1){
$(“#content”).animate({“right”:“-=198px”},“slow”);
位置--;
}
});
});
小提琴:


另一个解决方案是计算内容移动了多少次。您可以使用
$(“#content”).css('right')。因为你知道你总是以328px的步骤移动你的div,你可以把它除以328,得到它被点击的次数,我不喜欢用表格来做这个。。。div使代码更加流畅,并允许一个优雅的解决方案:活动div上的is(':last child')

但既然你们是用桌子做的,我可以想出两种方法

一种是使用计数器,然后对照表中的列数进行检查。如果每个步骤显示多个列,则为列/可见列的总数:

$(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 --;
        }
    });
});
$(函数(){
var位置=1;
$(“#左”)。单击(函数(){
变量大小=$(“#内容表”).find('tr').first().find('td').size();
如果(位置<(尺寸/2)){
$(“#content”).animate({“right”:“+=198px”},“slow”);
位置++;
}
});
$(“#右”)。单击(函数(){
如果(位置>1){
$(“#content”).animate({“right”:“-=198px”},“slow”);
位置--;
}
});
});
小提琴:


另一个解决方案是计算内容移动了多少次。您可以使用
$(“#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.
//向td添加一个类
//在你的js中。。。
$td_count=$(“.img_画廊”).size();
//现在你有很多不同的处理方法,
//你可以有一个计数器,或允许移动5*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.
//向td添加一个类
//在你的js中。。。
$td_count=$(“.img_画廊”).size();
//现在你有很多不同的处理方法,
//你可以有一个计数器,或允许移动5*328,任何你想要的。

update:update:谢谢,但“正确的btn”不起作用!你还把它改成了“1列”,我希望它是“2列”,就像我的例子。好吧,现在你的工作没有把“var count”改成“var position”,但就像我说的,我怎么能把“1列”改成“2列”?没问题。。。只需调整大小/2:(我还固定了变量名…很抱歉)好的,请您将您的解决方案作为答案,以便我可以接受。谢谢,但“正确的btn”不起作用!你还把它改成了“1列”,我希望它是“2列”,就像我的例子。好吧,现在你的工作没有把“var count”改成“var position”,但就像我说的,我怎么能把“1列”改成“2列”?没问题。。。2:(我还固定了变量名…很抱歉)好的,你能把你的解决方案作为答案,这样我就可以接受了。