From 51f33a44b5f2aa95e7470a0608c246e2ae63c124 Mon Sep 17 00:00:00 2001 From: Hyunje Alex Jun Date: Tue, 18 Aug 2015 03:26:19 +0900 Subject: [PATCH] Remove unused garbage rails before append a new one. This patch fixes #376. --- src/js/plugin/update-geometry.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/js/plugin/update-geometry.js b/src/js/plugin/update-geometry.js index 8de742e..af8adb9 100644 --- a/src/js/plugin/update-geometry.js +++ b/src/js/plugin/update-geometry.js @@ -60,10 +60,23 @@ module.exports = function (element) { i.contentWidth = element.scrollWidth; i.contentHeight = element.scrollHeight; + var existingRails; if (!element.contains(i.scrollbarXRail)) { + existingRails = d.queryChildren(element, '.ps-scrollbar-x-rail'); + if (existingRails.length > 0) { + existingRails.forEach(function (rail) { + d.remove(rail); + }); + } d.appendTo(i.scrollbarXRail, element); } if (!element.contains(i.scrollbarYRail)) { + existingRails = d.queryChildren(element, '.ps-scrollbar-y-rail'); + if (existingRails.length > 0) { + existingRails.forEach(function (rail) { + d.remove(rail); + }); + } d.appendTo(i.scrollbarYRail, element); }