Javascript 在每次单击和添加类时检查位置
如果显示第一个或最后一个选项卡,我希望将class.disabled添加到左侧和/或右侧控件(.tab left,.tab right),以便用户可以看到他们已到达末尾,并且不能再单击 现在,我需要这样做,以防止用户走到尽头Javascript 在每次单击和添加类时检查位置,javascript,jquery,jquery-plugins,Javascript,Jquery,Jquery Plugins,如果显示第一个或最后一个选项卡,我希望将class.disabled添加到左侧和/或右侧控件(.tab left,.tab right),以便用户可以看到他们已到达末尾,并且不能再单击 现在,我需要这样做,以防止用户走到尽头 if (tabs are at the end) { return; } 这适用于不能单击到末尾的用户,但是如果我在返回之前添加了类,问题是。禁用的类将不会被添加,直到选项卡到达末尾并且用户再次单击为止 if (tabs are at the end) {
if (tabs are at the end) {
return;
}
这适用于不能单击到末尾的用户,但是如果我在返回之前添加了类,问题是。禁用的类将不会被添加,直到选项卡到达末尾并且用户再次单击为止
if (tabs are at the end) {
$('.tab-right').addClass('disabled');
return;
}
我需要在显示最后一个选项卡时添加已禁用的类,而不是在用户尝试单击结束时添加
if (tabs are at the end) {
return;
}
这里有一个指向js fiddle的链接:您可以尝试的一个选项是在动画完成后启用/禁用左右按钮
$ul.filter(':not(:animated)').animate({
"left": dir + liWidth
}, {
complete: function () {
// Calculate the number of items in the container (without left and right navigation buttons).
var lisContainer = Math.round(($container.width() - $left.outerWidth() - $right.outerWidth()) / liWidth);
// Disable right button when list is moved to the left a number of items
// such as the remaining number of them is less or equal than the number
// of items that fit in the container.
$right.toggleClass('disabled', $li.length + $ul.position().left / liWidth <= lisContainer);
// Disable left button when list is in the origin.
$left.toggleClass('disabled', $ul.position().left === 0);
}
});
$ul.filter(':not(:animated)')。设置动画({
“左”:dir+liWidth
}, {
完成:函数(){
//计算容器中的项目数(不带左右导航按钮)。
var lisContainer=Math.round($container.width()-$left.outerWidth()-$right.outerWidth())/liWidth);
//当列表向左移动多个项目时禁用右按钮
//例如,它们的剩余数量小于或等于该数量
//装入容器的物品的数量。
$right.toggleClass('disabled',$li.length+$ul.position().left/liWidth所以基本上您希望在javascript返回之前添加类,这样用户就不需要再次单击了?是的,这正是我想要的。这正是我想要的。谢谢!