【发布时间】:2019-04-29 03:07:27
【问题描述】:
我正在处理滚动标签。下面是我的代码。我面临无法单击中间选项卡的问题。在右键单击选项卡上滚动逐渐移动它。我应该怎么做才能逐渐移动标签?请帮忙
var hidWidth;
var scrollBarWidths = 40;
var widthOfList = function() {
var itemsWidth = 0;
$('.list a').each(function() {
var itemWidth = $(this).outerWidth();
itemsWidth += itemWidth;
});
return itemsWidth;
};
var widthOfHidden = function() {
return (($('.wrapper').outerWidth()) - widthOfList() - getLeftPosi()) - scrollBarWidths;
};
var getLeftPosi = function() {
return $('.list').position().left;
};
var reAdjust = function() {
if (($('.wrapper').outerWidth()) < widthOfList()) {
$('.scroller-right').show().css('display', 'flex');
} else {
$('.scroller-right').hide();
}
if (getLeftPosi() < 0) {
$('.scroller-left').show().css('display', 'flex');
} else {
$('.item').animate({
left: "-=" + getLeftPosi() + "px"
}, 'slow');
$('.scroller-left').hide();
}
}
reAdjust();
$(window).on('resize', function(e) {
reAdjust();
});
$('.scroller-right').click(function() {
$('.scroller-left').fadeIn('slow');
$('.scroller-right').fadeOut('slow');
$('.list').animate({
left: "+=" + widthOfHidden() + "px"
}, 'slow', function() {
});
});
$('.scroller-left').click(function() {
$('.scroller-right').fadeIn('slow');
$('.scroller-left').fadeOut('slow');
$('.list').animate({
left: "-=" + getLeftPosi() + "px"
}, 'slow', function() {
});
});
小提琴http://jsfiddle.net/vedankita/2uswn4od/13
帮助我在按钮单击时缓慢滚动,以便我可以单击缓动选项卡。谢谢
【问题讨论】:
-
你想做什么?从您写的内容中理解起来很混乱。
-
当我点击右键滚动标签时,它会滚动到结束,这就是为什么我无法点击放在中间的标签
-
我可以毫无问题地单击选项卡 8
-
检查调整窗口大小你会明白我的问题。请最小化屏幕并检查
-
你应该逐渐将它移动 50px,它应该可以工作。
标签: javascript jquery html css bootstrap-4