All Projects → kimyvgy → simple-scrollspy

kimyvgy / simple-scrollspy

Licence: MIT license
Simple scrollspy without jQuery, no dependencies

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to simple-scrollspy

vanillajs-scrollspy
ScrollSpy in pure JavaScript
Stars: ✭ 47 (-11.32%)
Mutual labels:  scroll, scrollspy
vuejs-loadmore
A pull-down refresh and pull-up loadmore scroll component for Vue.js. Vue上拉加载下拉刷新组件
Stars: ✭ 62 (+16.98%)
Mutual labels:  scroll
RollingNotice-Swift
滚动公告、广告,支持灵活自定义cell。淘宝、口碑、京东、美团、天猫等等一切滚动广告 Roll Notice or Advertising, customize cell as UITableViewCell supported, Swift version is also ready
Stars: ✭ 109 (+105.66%)
Mutual labels:  scroll
QuickTraceiOSLogger
A real time iOS log trace tool, view iOS log with pc web browser under local area network, which will automatically scroll like xcode. 一个实时的iOS日志跟踪工具,在局域网中使用 PC Web 浏览器查看 iOS 日志,它将像xcode一样自动滚动。
Stars: ✭ 16 (-69.81%)
Mutual labels:  scroll
react-auto-scroll
Automatically scroll an element to the bottom
Stars: ✭ 28 (-47.17%)
Mutual labels:  scroll
react-use-scroll-position
A react hook to use scroll position
Stars: ✭ 45 (-15.09%)
Mutual labels:  scroll
react-scroll-trigger
📜 React component that monitors scroll events to trigger callbacks when it enters, exits and progresses through the viewport. All callback include the progress and velocity of the scrolling, in the event you want to manipulate stuff based on those values.
Stars: ✭ 126 (+137.74%)
Mutual labels:  scroll
h5-vue-scroller
inspired by iNoBounce, stop your iOS webapp from bouncing around when scrolling and more.
Stars: ✭ 30 (-43.4%)
Mutual labels:  scroll
universalSmoothScroll
A cross-browser smooth-scrolling API which supports multiple and interruptable scroll-animations on all DOM's elements, even at the same time!
Stars: ✭ 46 (-13.21%)
Mutual labels:  scroll
vue-scroll-snap
A super simple Vue component that allows fullscreen and horizontal scroll snapping.
Stars: ✭ 25 (-52.83%)
Mutual labels:  scroll
react-shadow-scroll
Component that customizes the list and inserts shadow when scrolling exists
Stars: ✭ 28 (-47.17%)
Mutual labels:  scroll
any-scroll
🚀 模拟scrollview, 支持pc/移动端, 让实现Tab/Slider等组件轻而易举.
Stars: ✭ 45 (-15.09%)
Mutual labels:  scroll
vue-scrollwatch
scrollspy
Stars: ✭ 59 (+11.32%)
Mutual labels:  scroll
JhScrollActionSheetView
JhScrollActionSheetView - UIcollectionView横向滚动,类似微博新版的详情页分享界面,可设置单排或双排显示,title不设置不显示title,如果想实现发送站内用户的功能,自己可以改一下代码
Stars: ✭ 13 (-75.47%)
Mutual labels:  scroll
onscroll-effect
A tiny JavaScript library to enable CSS animations when user scrolls.
Stars: ✭ 35 (-33.96%)
Mutual labels:  scroll
scrollRulerView
请使用 CYRuler (Please use CYRuler)
Stars: ✭ 31 (-41.51%)
Mutual labels:  scroll
anim-event
Event Manager for Animation
Stars: ✭ 25 (-52.83%)
Mutual labels:  scroll
NoobScroll
A lightweight jQuery Plugin that add some cool function to make scrolling more fun [Archive]
Stars: ✭ 43 (-18.87%)
Mutual labels:  scroll
scrollbox
A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.
Stars: ✭ 15 (-71.7%)
Mutual labels:  scroll
vue-scroll-progress
🎉 Page scroll progress bar component for @vuejs
Stars: ✭ 96 (+81.13%)
Mutual labels:  scroll

Simple Scrollspy

NPM version

Simple scrollspy is a lightweight javascript library without jQuery, no dependencies. It is used to make scrollspy effect for your menu, table of contents, etc. Only 1.4Kb.

This is a scrollspy demo for my menu in the navigation bar.

Install

  1. Via NPM:

Install NPM package - https://www.npmjs.com/package/simple-scrollspy:

npm install simple-scrollspy
  1. The other way, you also can inject simple-scrollspy.min.js file into your HTML code:
<script src="/path/to/dist/simple-scrollspy.min.js"></script>

Usages

Easy for using, syntax just like this:

scrollSpy(menuElement, 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:

  1. Added CSS for active class in your menu item. Because, this plugin do NOT include CSS.
  2. Added ID for your sections. Example: <section id="first-section">...</section>
  3. 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.

Arguments

  1. The menuElement is query selector to your menu. It is String or HTMLElement instance.
  2. The options is optional. It is type of Object which contains properties below:
Name Type Default Description
sectionClass String .scrollspy Query selector to your sections
menuActiveTarget String li > 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 menuActiveTarget
scrollContainer String, HTMLElement window User Defined Scrolling Container
smoothScroll Boolean, Object false Enable the smooth scrolling feature
smoothScrollBehavior Function undefined Define your smooth scroll behavior

ES6 example

import scrollSpy from 'simple-scrollspy'

const options = {
  sectionClass: '.scrollspy',           // Query selector to your sections
  menuActiveTarget: '.menu-item',       // Query selector to your elements that will be added `active` class
  offset: 100,                          // Menu item will active before scroll to a matched section 100px
  scrollContainer: '.scroll-container', // Listen scroll behavior on `.scroll-container` instead of `window`
}

// init:
scrollSpy(document.getElementById('main-menu'), options)

// or shorter:
scrollSpy('#main-menu', options)

Inject static file

<script src="/path/to/dist/simple-scrollspy.min.js"></script>
<script>
  window.onload = function () {
    scrollSpy('#main-menu', {
      sectionClass: '.scrollspy',
      menuActiveTarget: '.menu-item',
      offset: 100,
      // smooth scroll
      smoothScroll: true,
      smoothScrollBehavior: function(element) {
        console.log('run "smoothScrollBehavior"...', element)
        element.scrollIntoView({ behavior: 'smooth' }) // default behavior
      }
    })
  }
</script>

Smooth scroll

import jumpTo from 'jump.js'

scrollSpy('#main-menu', {
  // ....,

  // enable smooth scroll:
  // - true: enable with the default scroll behavior
  // - false: disable this feature
  // - object: enable with some options that will pass to `Element.scrollIntoView` or `smoothScrollBehavior`
  //   + Default behavior: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
  //   + Jump.js: https://www.npmjs.com/package/jump.js
  smoothScroll: true,

  // customize scroll behavior,
  // - default: Element.scrollIntoView({ ...smoothScroll, behavior: 'smooth' })
  // - customize: you can define your scroll behavior. Ex: use `jump.js`, jQuery, .etc
  smoothScrollBehavior: function(element, options) {
    // use `jump.js` instead of the default scroll behavior
    jumpTo(element, {
      duration: 1000,
      offset: -100,
    })
  }
})

Development

$ yarn install
$ yarn dev

Build

$ yarn build

or:

$ npm run build

The dist folder is automatically created and include file simple-scrollspy.min.js

Note

  • Feel free to make a pull request if you can, and create a Github issue if you come across one.
  • Don't forget to give a star if you feel that the library is helpful to you. It may save somebody a lot of trouble some day.

Helpful links

Licence

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].