Update thumbnails.js

This commit is contained in:
A-Circle Zhang 2018-09-29 12:06:19 +08:00 committed by GitHub
parent 892224d6c9
commit 7dfd75796f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -1,15 +1,16 @@
class Thumbnails {
constructor (options) {
this.container = options.container;
this.barWrap = options.barWrap;
this.barWidth = options.barWidth;
this.container.style.backgroundImage = `url('${options.url}')`;
this.events = options.events;
}
resize (width, height) {
resize (width, height, barWrapWidth) {
this.container.style.width = `${width}px`;
this.container.style.height = `${height}px`;
this.container.style.top = `${-height + 2}px`;
this.barWidth = barWrapWidth;
}
show () {
@ -18,8 +19,8 @@ class Thumbnails {
}
move (position) {
this.container.style.backgroundPosition = `-${(Math.ceil(position / this.barWrap.offsetWidth * 100) - 1) * 160}px 0`;
this.container.style.left = `${Math.min(Math.max(position - this.container.offsetWidth / 2, -10), this.barWrap.offsetWidth - 150)}px`;
this.container.style.backgroundPosition = `-${(Math.ceil(position / this.barWidth * 100) - 1) * 160}px 0`;
this.container.style.left = `${Math.min(Math.max(position - this.container.offsetWidth / 2, -10), this.barWidth - 150)}px`;
}
hide () {