diff --git a/bower.json b/bower.json index f49f9a3..f553ef7 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "gemini-scrollbar", "main": "index.js", - "version": "0.0.2", + "version": "0.0.3", "homepage": "https://github.com/noeldelgado/gemini-scrollbar", "authors": [ "Noel Delgado " diff --git a/index.js b/index.js index 90ab2e6..fbce2e4 100644 --- a/index.js +++ b/index.js @@ -40,6 +40,7 @@ function GeminiScrollbar(config) { this.element = null; this.autoshow = false; + this.createElements = true; Object.keys(config || {}).forEach(function (propertyName) { this[propertyName] = config[propertyName]; @@ -77,13 +78,22 @@ this._document = document; this._window = window; - this._viewElement = document.createElement('div'); - this._scrollbarVerticalElement = document.createElement('div'); - this._thumbVerticalElement = document.createElement('div'); - this._scrollbarHorizontalElement = document.createElement('div'); - this._thumbHorizontalElement = document.createElement('div'); - while(this.element.childNodes.length > 0) { - this._viewElement.appendChild(this.element.childNodes[0]); + + if (this.createElements === true) { + this._viewElement = document.createElement('div'); + this._scrollbarVerticalElement = document.createElement('div'); + this._thumbVerticalElement = document.createElement('div'); + this._scrollbarHorizontalElement = document.createElement('div'); + this._thumbHorizontalElement = document.createElement('div'); + while(this.element.childNodes.length > 0) { + this._viewElement.appendChild(this.element.childNodes[0]); + } + } else { + this._viewElement = this.element.querySelector('.' + CLASSNAMES.view); + this._scrollbarVerticalElement =this.element.querySelector('.' + CLASSNAMES.verticalScrollbar.split(' ').join('.')); + this._thumbVerticalElement = this._scrollbarVerticalElement.querySelector('.' + CLASSNAMES.thumb); + this._scrollbarHorizontalElement = this.element.querySelector('.' + CLASSNAMES.horizontalScrollbar.split(' ').join('.')); + this._thumbHorizontalElement = this._scrollbarHorizontalElement.querySelector('.' + CLASSNAMES.thumb); } this.element.classList.add(CLASSNAMES.element); diff --git a/package.json b/package.json index 3ed7021..06fa060 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gemini-scrollbar", - "version": "0.0.2", + "version": "0.0.3", "description": "Custom scrollbars with native scrolling", "license": "MIT", "repository": "noeldelgado/gemini-scrollbar.git",