Add update and destroy function, enhance css.

this is the release version!
This commit is contained in:
Hyunje Alex Jun
2012-11-10 03:13:47 +09:00
parent 474351752d
commit a96c918dc8
4 changed files with 80 additions and 19 deletions
+37 -5
View File
@@ -2,7 +2,21 @@
* Licensed under the MIT License
*/
((function($) {
$.fn.perfectScrollbar = function() {
$.fn.perfectScrollbar = function(option) {
if(option === 'update') {
$(this).data('perfect_scrollbar_update')();
return;
}
else if(option === 'destroy') {
$(this).data('perfect_scrollbar_destroy')();
return;
}
if($(this).data('perfect_scrollbar')) {
// if there's already perfect_scrollbar
return;
}
var $this = $(this).addClass('ps-container'),
$content = $(this).children(),
$scrollbar_x = $("<div class='ps-scrollbar-x'></div>").appendTo($this),
@@ -159,11 +173,29 @@
});
};
var destroy = function() {
$scrollbar_x.remove();
$scrollbar_y.remove();
$this.unbind('mousewheel');
$(window).unbind('mousemove.perfect-scroll');
$(window).unbind('mouseup.perfect-scroll');
$this.data('perfect_scrollbar', null);
$this.data('perfect_scrollbar_update', null);
$this.data('perfect_scrollbar_destroy', null);
};
var initialize = function() {
updateBarSizeAndPosition();
bindMouseScrollXHandler();
bindMouseScrollYHandler();
if($this.mousewheel) bindMouseWheelHandler();
$this.data('perfect_scrollbar', true);
$this.data('perfect_scrollbar_update', updateBarSizeAndPosition);
$this.data('perfect_scrollbar_destroy', destroy);
};
// initialize
updateBarSizeAndPosition();
bindMouseScrollXHandler();
bindMouseScrollYHandler();
if($this.mousewheel) bindMouseWheelHandler();
initialize();
return $this;
};