Skip to content

Commit

Permalink
Fix removePsClasses() to remove classes properly
Browse files Browse the repository at this point in the history
Fix #698.
  • Loading branch information
Hyunje Jun committed Oct 19, 2017
1 parent 4479996 commit ae6cf02
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
49 changes: 49 additions & 0 deletions examples/init-and-remove.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<link href="../css/perfect-scrollbar.css" rel="stylesheet">
<script src="../dist/perfect-scrollbar.js"></script>
<style>
#container {
position: relative;
margin: 0px auto;
padding: 0px;
width: 600px;
height: 400px;
overflow: auto;
}
#container .content {
background-image: url('./assets/azusa.jpg');
width: 1280px;
height: 720px;
}
</style>
</head>
<body>
<div id="container">
<div class="content">
</div>
</div>

<div style="width: 600px; text-align: center; margin: 30px auto;">
<button id="init">init</button>
<button id="remove">remove</button>
</div>

<script>
var $ = document.querySelector.bind(document);

var ps;

$('#init').addEventListener('click', () => {
if (ps) ps.destroy();
ps = new PerfectScrollbar('#container');
});

$('#remove').addEventListener('click', () => {
if (ps) ps.destroy();
ps = null;
});
</script>
</body>
</html>
10 changes: 4 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,9 @@ export default class PerfectScrollbar {
}

removePsClasses() {
for (let i = 0; i < this.element.classList.length; i++) {
const className = this.element.classList[i];
if (className === 'ps' || className.indexOf('ps-') === 0) {
this.element.classList.remove(className);
}
}
this.element.className = this.element.className
.split(' ')
.filter(name => !name.match(/^ps([-_].+|)$/))
.join(' ');
}
}

0 comments on commit ae6cf02

Please sign in to comment.