/*
* Copyright (c) Baidu, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import QuestionGuideBase from '../base';
import type {QuestionGuideEvents} from '../interface';
export default class QuestionGuide extends QuestionGuideBase {
static template = /* html */ `
`;
static trimWhitespace = QuestionGuideBase.trimWhitespace;
static components = QuestionGuideBase.components;
swiperList: HTMLElement;
initData() {
return {
...super.initData(),
_transOffset: 0,
_showPrev: false,
_showNext: true
};
}
attached() {
const swiperList = this.ref('swiperList') as unknown as HTMLElement;
this.swiperList = swiperList;
this.nextTick(() => {
const windowWidth = swiperList.offsetWidth;
const totalWidth = swiperList.scrollWidth;
if (totalWidth <= windowWidth) {
this.data.set('_showNext', false);
}
});
}
onPrev() {
this.fire('scroll', {
action: 'slideslip'
});
let oldTransOffset = this.data.get('_transOffset');
// swiper窗口
const swiperList = this.swiperList;
// 视口宽度
const windowWidth = swiperList.offsetWidth;
if (oldTransOffset + windowWidth >= 0) {
this.data.set('_showPrev', false);
this.data.set('_transOffset', 0);
}
else {
this.data.set('_transOffset', oldTransOffset + windowWidth);
}
this.data.set('_showNext', true);
}
onNext() {
this.fire('scroll', {
action: 'slideslip'
});
let oldTransOffset = this.data.get('_transOffset');
// swiper窗口
const swiperList = this.swiperList;
// 视口宽度
const windowWidth = swiperList.offsetWidth;
const totalWidth = swiperList.scrollWidth;
if (oldTransOffset - windowWidth <= windowWidth - totalWidth) {
this.data.set('_showNext', false);
this.data.set('_transOffset', windowWidth - totalWidth);
}
else {
this.data.set('_transOffset', oldTransOffset - windowWidth);
}
this.data.set('_showPrev', true);
}
}