小改动;

master
zhizou 2019-06-25 18:15:17 +08:00
parent 68088578de
commit 044c830894
1 changed files with 31 additions and 20 deletions

View File

@ -60,8 +60,13 @@ layui.define(["element", "jquery"], function (exports) {
superWidth = parseInt(superEle.width()) - 40 * 3,//可显示的宽度
subWidth = ele.outerWidth(),//当前元素宽度
elePrevAll = ele.prevAll(),//左边的所有同级元素
leftWidth = 0;//左边距离
leftWidth = 0,//左边距离
postLeft = Math.abs(contEle.position().left);//当前移动的位置
var maxMoveWidth = contWidth - superWidth;//最大可移动的宽度
/*console.log("maxMoveWidth" + maxMoveWidth);
console.log("superWidth" + superWidth);
console.log("contWidth" + contWidth);*/
for (let i = 0; i < elePrevAll.length; i++) {
leftWidth += $(elePrevAll[i]).outerWidth() * 1;
}
@ -69,20 +74,25 @@ layui.define(["element", "jquery"], function (exports) {
/**
* 移动tab栏的位置
*/
if (leftWidth + subWidth > superWidth) {
var moveWidth = leftWidth - subWidth;
if (moveWidth > contWidth - superWidth) {
contEle.animate({
left: -(contWidth - superWidth)
}, 50);
} else {
contEle.animate({
left: -moveWidth
}, 50);
var showPost = leftWidth - postLeft;//当前点击的元素位置(显示区域的位置)
var halfPlace = parseInt(superWidth / 2);//可显示的宽度的一半
if (halfPlace < showPost) {//从右往左移动
var tempMove = leftWidth - subWidth;//预留一部分距离
if(tempMove > maxMoveWidth){//当前移动的距离超过最大可移动的宽度
tempMove = maxMoveWidth;
}
} else {
contEle.animate({
left: -leftWidth
left: -tempMove
}, 50);
}else{//从左往右移动
console.log("从左往右移动");
var tempMove = leftWidth - halfPlace;//预留一部分距离
if(tempMove < 0){
tempMove = 0;
}
contEle.animate({
left: -tempMove
}, 50);
}
}
@ -400,6 +410,7 @@ layui.define(["element", "jquery"], function (exports) {
tips: [1, '#000'],
time: 2000
});
moveLeft = -moveWidth;
}
if (superWidth + Math.abs(moveLeft) >= contWidth) {
moveLeft = -moveWidth;