Skip to content

Commit

Permalink
refactor(api/destroy): destroy scrollbars without scrolling to top
Browse files Browse the repository at this point in the history
Resolve #67
  • Loading branch information
idiotWu committed Aug 23, 2017
1 parent 9a353b2 commit 3c430bc
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/apis/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,25 @@ SmoothScrollbar.prototype.destroy = function (isRemoval) {
// remove form sbList
sbList.delete(container);

if (isRemoval) return;

// restore DOM
this.scrollTo(0, 0, 300, () => {
// check if element has been removed from DOM
if (!container.parentNode) {
return;
}

// reset scroll position
setStyle(container, {
overflow: '',
});
// check if element has been removed from DOM
if (isRemoval || !container.parentNode) {
return;
}

container.scrollTop = container.scrollLeft = 0;
// reset content
const childNodes = [...content.childNodes];

// reset content
const childNodes = [...content.childNodes];
while (container.firstChild) {
container.removeChild(container.firstChild);
}

while (container.firstChild) {
container.removeChild(container.firstChild);
}
childNodes.forEach((el) => container.appendChild(el));

childNodes.forEach((el) => container.appendChild(el));
// reset scroll position
setStyle(container, {
overflow: '',
});

container.scrollTop = this.scrollTop;
container.scrollLeft = this.scrollLeft;
};

0 comments on commit 3c430bc

Please sign in to comment.