diff --git a/demo/chart.js b/demo/chart.js index e97b076ce..27004aa09 100644 --- a/demo/chart.js +++ b/demo/chart.js @@ -145,7 +145,9 @@ var billboardDemo = { type = type.replace("#", "").split("."); - this.generate(type[0], type[1]); + try { + this.generate(type[0], type[1]); + } catch(e) {} this.$title.innerHTML = type[1] .replace(/([A-Z][a-z])/g, " $1") @@ -162,8 +164,23 @@ var billboardDemo = { // add selected class $selected = this.$list.querySelector("[href='#"+ type.join(".") +"']"); $selected.className += this.selectedClass; - + window.scrollTo(0, 0); + + !this.isVisible($selected) && $selected.scrollIntoView({ + behavior: "auto", + block: "start" + }); + }, + + isVisible($el) { + const {clientWidth, clientHeight} = document.documentElement; + const {top, right, bottom, left} = $el.getBoundingClientRect(); + + return top <= clientHeight && + right >= 0 && + bottom >= 0 && + left <= clientWidth; }, /** @@ -229,10 +246,10 @@ var billboardDemo = { '// import bb, {'+ code.esm.join(", ") +'} from "billboard.js";\r\n'; if (hasPlugin) { - this.$code.innerHTML += '// import '+ pluginName +' from "billboard.js/dist/plugin/billboardjs-plugin-'+ pluginName +'";'; + this.$code.innerHTML += '// import '+ pluginName +' from "billboard.js/dist/plugin/billboardjs-plugin-'+ pluginName +'";\r\n'; } - this.$code.innerHTML += '\r\n\r\n'+ code.data; + this.$code.innerHTML += '\r\n'+ code.data; this.$code.scrollTop = 0; hljs.highlightBlock(this.$html); diff --git a/demo/index.html b/demo/index.html index f68f2c847..2e6e8dd25 100644 --- a/demo/index.html +++ b/demo/index.html @@ -115,49 +115,55 @@
- Checkout total of examples, by clicking menu . -
- -
-
- • Try it out by editing below code or click right sided buttons.
- *for ESM imports usage example, checkout this link.
-
+ Checkout total of examples, by clicking menu . +
+ +
+
+ • Try it out by editing below code or click right sided buttons.
+ *for ESM imports usage example, checkout this link.
+