Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove function issues #44

Open
Jevedor opened this issue Jun 6, 2014 · 4 comments · Fixed by geoscan/jquery-custom-scrollbar#1 · May be fixed by #68 or 3lvcz/jquery-custom-scrollbar#1
Open

Remove function issues #44

Jevedor opened this issue Jun 6, 2014 · 4 comments · Fixed by geoscan/jquery-custom-scrollbar#1 · May be fixed by #68 or 3lvcz/jquery-custom-scrollbar#1

Comments

@Jevedor
Copy link

Jevedor commented Jun 6, 2014

I am finding the remove functionality does not work properly.

As per the documentation this should remove the markup:

$(".container").customScrollbar("remove");

The issue is, it does not properly remove the added "overview" and "viewport" elements. Looking in the code the issue is the use of unwrap.

removeScrollbarComponents: function () {
this.removeScrollbar("vertical");
this.removeScrollbar("horizontal");
if (this.overviewAdded)
this.$element.unwrap();
if (this.viewPortAdded)
this.$element.unwrap();
},

unwrap removes what is wrapping the element not what the element is wrapping. Thus this function ends up removing elements above the container instead of removing viewport and overview elements.

@Jevedor
Copy link
Author

Jevedor commented Jun 6, 2014

A bit more info.
The culprit to this issue is that in the function that adds the viewport and overview elements the code uses the wrapInner method.

addScrollBarComponents: function () {
this.assignViewPort();
if (this.$viewPort.length == 0) {
this.$element.wrapInner("<div class="viewport" />");
this.assignViewPort();
this.viewPortAdded = true;
}
this.assignOverview();
if (this.$overview.length == 0) {
this.$viewPort.wrapInner("<div class="overview" />");
this.assignOverview();
this.overviewAdded = true;
}
this.addScrollBar("vertical", "prepend");
this.addScrollBar("horizontal", "append");
},

The unwrap function would work if we used wrap instead of wrapInner. Although I like the idea of it putting the elements inside instead of outside.

here is a possible way to resolve the issue.

removeScrollbarComponents: function () {
this.removeScrollbar("vertical");
this.removeScrollbar("horizontal");
if (this.overviewAdded)
this.$overview.replaceWith(this.$overview.contents());
if (this.viewPortAdded)
this.$viewPort.replaceWith(this.$viewPort.contents());
},

@karanveerm
Copy link

I was having the same problem, Jevedor's suggestion worked for me.

@hunhavoc
Copy link

Thanks, Jevedor's solution solved my problem!

@gcirone
Copy link

gcirone commented Aug 18, 2016

Yes Jevedor's solution working good +1

Vineg added a commit to Vineg/jquery-custom-scrollbar that referenced this issue Apr 22, 2019
Vineg added a commit to geoscan/jquery-custom-scrollbar that referenced this issue Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants