From 07b0b1bb6d6b571873ccd1d6d8b72d0c92c0af65 Mon Sep 17 00:00:00 2001 From: Mauricio Dziedzinski Date: Fri, 15 May 2020 22:24:22 +0200 Subject: [PATCH] feat: make possible to use different tags as menu items --- README.md | 15 ++++++++++++++- src/scrollactive.vue | 19 +++++++++++++------ src/utils/getSectionIdFromElement.js | 7 +++++++ src/utils/getSectionSelector.js | 8 ++++++++ src/utils/index.js | 3 ++- src/utils/map.js | 2 -- 6 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 src/utils/getSectionIdFromElement.js create mode 100644 src/utils/getSectionSelector.js delete mode 100644 src/utils/map.js diff --git a/README.md b/README.md index 9bf3ec7..4293011 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ If you're not running any transpiler like babel, you'll most likely need to inst ## Usage -You should wrap your menu in a `` tag (which will be your nav) and add a `.scrollactive-item` class in your `` tags as I show in the example below: +The primary way to use the plugin is to wrap your menu in a `` tag (which will be your nav) and add a `.scrollactive-item` class in your `` tags as I show in the example below: ```html @@ -54,6 +54,19 @@ You should wrap your menu in a `` tag (which will be your nav) and You can follow whatever structure you wish, just make sure to set the `.scrollactive-item` class in the items you want to highlight and set its `href` with a valid element ID that you would like to track while scrolling. +The secondary way to use it is almost the same as the primary but instead of relying on `href` to find your sections you'll need to set a data attribute `data-section-selector` on your elements with the section selector you wish to have. + +```html + + Home + About Us + Portfolio + Contact + +``` + +As you can see this gives you more freedom to choose different tags and you can use whatever CSS selector you find necessary, but it's important to notice that `data-section-selector` takes precedence over `href`, so if you have a tag `` it will completely ignore the `#section-1` and use `#another-section` instead. + ## Events Scrollactive will emit an `itemchanged(event, currentItem, lastActiveItem)` event when an active menu item is changed to another. You can catch that event doing as the example below: diff --git a/src/scrollactive.vue b/src/scrollactive.vue index b7d101f..0f2a89b 100644 --- a/src/scrollactive.vue +++ b/src/scrollactive.vue @@ -1,7 +1,14 @@