瀏覽代碼

Update thumbnails.js

A-Circle Zhang 7 年之前
父節點
當前提交
7dfd75796f
共有 1 個文件被更改,包括 5 次插入4 次删除
  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 () {