improve the code of the smoothscrolling on the doc page
This commit is contained in:
parent
cebda05598
commit
d700f05c90
26
scribbler.js
26
scribbler.js
@ -81,7 +81,8 @@ function setActiveLink(event) {
|
|||||||
event.target.classList.add('selected');
|
event.target.classList.add('selected');
|
||||||
}
|
}
|
||||||
|
|
||||||
function smoothScrollTo(element, event) {
|
function smoothScrollTo(i, event) {
|
||||||
|
var element = sections[i];
|
||||||
setActiveLink(event);
|
setActiveLink(event);
|
||||||
|
|
||||||
window.scrollTo({
|
window.scrollTo({
|
||||||
@ -92,26 +93,9 @@ function smoothScrollTo(element, event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (btns.length && sections.length > 0) {
|
if (btns.length && sections.length > 0) {
|
||||||
// for (var i = 0; i<btns.length; i++) {
|
for (var i = 0; i<btns.length; i++) {
|
||||||
// btns[i].addEventListener('click', function(event) {
|
btns[i].addEventListener('click', smoothScrollTo.bind(this,i));
|
||||||
// smoothScrollTo(sections[i], event);
|
}
|
||||||
// });
|
|
||||||
// }
|
|
||||||
btns[0].addEventListener('click', function (event) {
|
|
||||||
smoothScrollTo(sections[0], event);
|
|
||||||
});
|
|
||||||
|
|
||||||
btns[1].addEventListener('click', function (event) {
|
|
||||||
smoothScrollTo(sections[1], event);
|
|
||||||
});
|
|
||||||
|
|
||||||
btns[2].addEventListener('click', function (event) {
|
|
||||||
smoothScrollTo(sections[2], event);
|
|
||||||
});
|
|
||||||
|
|
||||||
btns[3].addEventListener('click', function (event) {
|
|
||||||
smoothScrollTo(sections[3], event);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix menu to page-top once user starts scrolling
|
// fix menu to page-top once user starts scrolling
|
||||||
|
Loading…
Reference in New Issue
Block a user