mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
parent
cc95c58635
commit
0d9850a11d
@ -38,8 +38,9 @@ VantComponent({
|
|||||||
animated: {
|
animated: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
observer() {
|
observer() {
|
||||||
this.setTrack();
|
this.children.forEach((child: TrivialInstance, index: number) =>
|
||||||
this.children.forEach((child: TrivialInstance) => child.updateRender());
|
child.updateRender(index === this.data.currentIndex, this)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
swipeable: Boolean,
|
swipeable: Boolean,
|
||||||
@ -100,7 +101,7 @@ VantComponent({
|
|||||||
lazyRender: {
|
lazyRender: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true
|
value: true
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data: {
|
data: {
|
||||||
@ -122,7 +123,6 @@ VantComponent({
|
|||||||
container: () => this.createSelectorQuery().select('.van-tabs')
|
container: () => this.createSelectorQuery().select('.van-tabs')
|
||||||
});
|
});
|
||||||
this.setLine(true);
|
this.setLine(true);
|
||||||
this.setTrack();
|
|
||||||
this.scrollIntoView();
|
this.scrollIntoView();
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -206,7 +206,6 @@ VantComponent({
|
|||||||
|
|
||||||
wx.nextTick(() => {
|
wx.nextTick(() => {
|
||||||
this.setLine();
|
this.setLine();
|
||||||
this.setTrack();
|
|
||||||
this.scrollIntoView();
|
this.scrollIntoView();
|
||||||
|
|
||||||
this.trigger('input');
|
this.trigger('input');
|
||||||
@ -246,7 +245,9 @@ VantComponent({
|
|||||||
const width = lineWidth !== -1 ? lineWidth : rect.width / 2;
|
const width = lineWidth !== -1 ? lineWidth : rect.width / 2;
|
||||||
const height =
|
const height =
|
||||||
lineHeight !== -1
|
lineHeight !== -1
|
||||||
? `height: ${addUnit(lineHeight)}; border-radius: ${addUnit(lineHeight)};`
|
? `height: ${addUnit(lineHeight)}; border-radius: ${addUnit(
|
||||||
|
lineHeight
|
||||||
|
)};`
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
let left = rects
|
let left = rects
|
||||||
@ -273,22 +274,6 @@ VantComponent({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
setTrack() {
|
|
||||||
const { animated, duration, currentIndex } = this.data;
|
|
||||||
|
|
||||||
if (!animated) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setData({
|
|
||||||
trackStyle: `
|
|
||||||
transform: translate3d(${-100 * currentIndex}%, 0, 0);
|
|
||||||
-webkit-transition-duration: ${duration}s;
|
|
||||||
transition-duration: ${duration}s;
|
|
||||||
`
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
// scroll active tab into view
|
// scroll active tab into view
|
||||||
scrollIntoView() {
|
scrollIntoView() {
|
||||||
const { currentIndex, scrollable } = this.data;
|
const { currentIndex, scrollable } = this.data;
|
||||||
|
@ -53,7 +53,10 @@
|
|||||||
bind:touchend="onTouchEnd"
|
bind:touchend="onTouchEnd"
|
||||||
bind:touchcancel="onTouchEnd"
|
bind:touchcancel="onTouchEnd"
|
||||||
>
|
>
|
||||||
<view class="{{ utils.bem('tabs__track', [{ animated }]) }} van-tabs__track" style="{{ trackStyle }}">
|
<view
|
||||||
|
class="{{ utils.bem('tabs__track', [{ animated }]) }} van-tabs__track"
|
||||||
|
style="{{ getters.trackStyle({ duration, currentIndex, animated }) }}"
|
||||||
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
@ -51,5 +51,18 @@ function tabStyle(
|
|||||||
return styles.join(';');
|
return styles.join(';');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trackStyle(data) {
|
||||||
|
if (!data.animated) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'transform: translate3d(' + -100 * data.currentIndex + '%, 0, 0)',
|
||||||
|
'-webkit-transition-duration: ' + data.duration + 's',
|
||||||
|
'transition-duration: ' + data.duration + 's'
|
||||||
|
].join(';');
|
||||||
|
}
|
||||||
|
|
||||||
module.exports.tabClass = tabClass;
|
module.exports.tabClass = tabClass;
|
||||||
module.exports.tabStyle = tabStyle;
|
module.exports.tabStyle = tabStyle;
|
||||||
|
module.exports.trackStyle = trackStyle;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user