Browse Source

Update thumbnails.js

A-Circle Zhang 6 years ago
parent
commit
7dfd75796f
1 changed files with 5 additions and 4 deletions
  1. 5 4
      src/js/thumbnails.js

+ 5 - 4
src/js/thumbnails.js

@@ -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 () {