From 369071a5fe8c65d07664ac04b7bbea348960ddb0 Mon Sep 17 00:00:00 2001 From: sight <26325820+Sight-wcg@users.noreply.github.com> Date: Tue, 19 Nov 2024 17:05:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(tab):=20=E6=B7=BB=E5=8A=A0=20shadow=20?= =?UTF-8?q?=E5=8A=A9=E6=89=8B=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/element.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modules/element.js b/src/modules/element.js index ad126692..35d99957 100644 --- a/src/modules/element.js +++ b/src/modules/element.js @@ -328,6 +328,7 @@ layui.define('jquery', function(exports){ titleElem.append(borderBottomPatch); } titleElem.addClass(SCROLL); + call.tabUpdateShadowHelper(tabElem, titleElem); if(checkOverflow){ // TODO 计算所有选项卡宽度之和,以规避 float 带来的瑕疵? @@ -355,6 +356,7 @@ layui.define('jquery', function(exports){ } var distance = 30 * (direction > 0 ? 1 : -1); el.scrollLeft(el.scrollLeft() + distance); + call.tabUpdateShadowHelper(tabElem, el); }) }else{ titleElem.find('.'+ BAR).remove(); @@ -362,6 +364,12 @@ layui.define('jquery', function(exports){ borderBottomPatch.width('100%'); } } + ,tabUpdateShadowHelper: function(targetEl, scrollEl){ + var scrollLeft = scrollEl.scrollLeft(); + // 阴影 helper 类 + targetEl.toggleClass('layui-tab-has-start-shadow', scrollLeft > 0); + targetEl.toggleClass('layui-tab-has-end-shadow', scrollLeft < scrollEl.prop('scrollWidth') - scrollEl.outerWidth() - 1); + } //点击一级菜单 /*