1.0.0 • Published 12 months ago

@antonio-goncalves/hover-on-scroll v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

HoverOnScroll

Sample video

HoverOnScroll is a JavaScript library that adds support to hover effects while scrolling the window or a container, it was developed to overcome the limitation of browsers to apply the css :hover effect during scroll

Sample

The sample available on the dev folder could be run following those steps

npm install
npm run start

Properties

import HoverOnScroll from "@antonio-goncalves/hover-on-scroll";

const hoverOnScroll = new HoverOnScroll([elementToHover1,elementToHover2],options)

function destroy(){
    hoverOnScroll.destroy()
}

ElementToHover

First parameter of HoverOnScroll constructor

NameTypeis OptionalDescription
elementClassstringnoClass of the element where the "hoverClass" must be applied when hovering
hoverClassstringnoClass which will be applied to the element to enable the hover effect

Options

Second parameter of HoverOnScroll constructor, this parameter is optional

NameTypeis OptionalDescription
mouseOffsetnumberyesMinimum Y value to be considered when listening the mouse position, this could be useful to allow the hover effect behind navbars
initialMousePosition{x:Number, y:Number}yesInitial mouse position
scrollingElementsElementyesElements where the onScroll event will be attached, useful for containers with scroll
touchBehaviourTouchBehaviouryesOptions specific for touch devices

TouchBehaviour

Those options are only relevant for touch devices.

NameTypeis OptionalDescription
scrollWhenTouchbooleanyesSet to true, to scroll to the element on touch
offsetWhenScrollNumberyesvertical offset for the behaviour described on the previous option, is useful to place the content below a navbar
 
1.0.0

12 months ago

0.0.1

12 months ago