GithubHelp home page GithubHelp logo

nathan2-d / scrollutil Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 26 KB

Scroll Utility - native js (WIP)

License: MIT License

JavaScript 100.00%
requestanimationframe scrolling customevent es6-javascript experimentation

scrollutil's Introduction

ScrollUtil.js

[WIP] do not use

pull request welcome ;)

Demo

basic scrollspy

Getting Started

Clone this repository

git clone https://github.com/Nathan2-D/ScrollUtil.git

Options

CURRENT OPTIONS

SmoothScroll : (optional/default:false) -> assume usage of new 'scroll-behavior' css property and fallback for browsers not supporting it listen : -> array of objects representing elements SU will track while scroll happen and their configurations : selector : (required) - SU will track all these elements and update their state based on update update : (activation logic) eg : if _touching, element is active only when touching the computed trigger line trigger (optional/default:1) represent a percentage of available window height, used to calculate trigger line. like so: triggerLine = (windowHeight/100)*trigger) events : -isEligible : name of the event fired when element meet condition -lostEligibility : name of the event fired when element lost eligibility (noway)

INCOMING
  • offset for fixed nav (any direction)
  • allow multiples selector and updates methods (pipe?) (eg: 'update' : '_visible|_touching')

Template for testing (emmet)

!>.container>(#nav>ul>li*12>a[href=#section$]{Section $})+section.myCssClass#section$*12

Init

var test = new ScrollUtil({
  'smoothScroll' : true,
  'listen' : [
    {'selector' : '.myCssClass', 'update' : '_touching', 'trigger' : 50, 'events' : {'isEligible' : 'myCustomEvent', 'lostEligibility' : 'myOtherCustomEvent'} }
  ]
});

Listening Custom Events

let curr
// happen when elements is eligible
window.addEventListener('myCustomEvent', (e) => {
  if(!curr){
    curr = e.detail.activeElement
  }
  // change target when we receive a new one
  if(curr != e.detail.activeElement){
    curr = e.detail.activeElement
  }
  // getPair() Element methods / retrieve (href)targeting element
  curr.getPair().classList.add('is-active')
});

// happen when element lost eligibility
window.addEventListener('myOtherCustomEvent', (e) => {
  elem = e.detail.activeElement
  elem.getPair().classList.remove('is-active')
});

Authors

  • Nathanaël Demeuse - Initial work - Nathan2-D

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.