Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@sidsbrmnn/scrollspy
Advanced tools
Changelog
[1.1.0] - 2022-01-06
onActive
callback function (#6)Readme
A simple lightweight JavaScript library without jQuery or any other dependencies to handle scroll spying on static webpages.
via NPM
Install it using npm
npm install --save @sidsbrmnn/scrollspy
Use the minified script from unpkg.com
<script src="https://unpkg.com/@sidsbrmnn/scrollspy@1.x/dist/scrollspy.min.js"></script>
Easy for using, syntax just like this:
scrollSpy(menu, options)
This little plugin will add active
class into your existing menu item when you scroll your page to a matched section by ID.
If you are giving it a try, make sure that you:
Added CSS for active
class in your menu item. Because, this plugin do NOT include CSS.
Create your sections.
Example: <section id="first-section">...</section>
Added an attribute which is an section ID into your menu items. Default is href
.
Example: "href"="#first-section"
.
You also replace href
with the other name by hrefAttribute
in options
.
The menu
is query selector to your menu. It is string
or HTMLElement
instance.
The options
is optional. It is type of object
which contains properties below:
Name | Type | Default | Description |
---|---|---|---|
sectionSelector | string | section | Query selector to your sections |
targetSelector | string | a | Element will be added active class |
offset | number | 0 | Offset number |
hrefAttribute | string | href | The menu item's attribute name which contains section ID |
activeClass | string | active | Active class name will be added into targetSelector |
isActive | function | null | A callback method that's called with the current menuItem and section |
import scrollSpy from '@sidsbrmnn/scrollspy'
const options = {
sectionSelector: 'section', // Query selector to your sections
targetSelector: '.nav-link', // Query selector to your elements that will be added `active` class
offset: 100 // Menu item will active before scroll to a matched section 100px
}
// Initialize
scrollSpy(document.getElementById('navMain'), options)
// Shorter way
scrollSpy('#navMain', options)
<script src="/path/to/dist/scrollspy.min.js"></script>
<script>
window.onload = function () {
scrollSpy('#navMain', {
sectionSelector: 'section',
targetSelector: '.nav-link',
offset: 100
});
}
</script>
FAQs
A simple lightweight JavaScript library without jQuery or any other dependencies to handle scroll spying on static webpages.
The npm package @sidsbrmnn/scrollspy receives a total of 927 weekly downloads. As such, @sidsbrmnn/scrollspy popularity was classified as not popular.
We found that @sidsbrmnn/scrollspy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.