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