varss=newScrollSwipe({target: document,// Element must be a single dom-node per ScrollSwipe InstancescrollSensitivity: 0,// The lower the number, the more sensitivetouchSensitivity: 0,// The lower the number, the more senitivescrollPreventDefault: true,// prevent default option for scroll eventstouchPreventDefault: true,// prevent default option for touch eventsscrollCb: scrollCb,// The action you wish to perform when a scroll reacts (details below)touchCb: touchCb,// The action you wish to perform when a touch reacts (details below)dragCb: dragCb// gives you the delta x/y of touch events. You'll also need touchCb to be set.});
Scroll API && Touch API
//Example callbacks for the ScrollSwipe instance above ^^/** * @param {Object} data - returns the following * startEvent - Event that triggered this action * lastEvent - Last Event at the end of action * scrollPending - state of instance's scrollPending property (will always come back true after a successful event) * direction - 'VERTICAL' || 'HORIZONTAL' for mapping vertical/horizontal actions from the event; * intent - 0 || 1 for mapping up/down && left/right actions from the event */functionscrollCb(data){//do animations, state changes/eval or something async, then open the listener back up.ss.listen();}functiontouchCb(data){//the exact same behavior as scrollCb ^^ appliesss.listen();}/** * @param {Object} data - returns the following * x - delta X * y - delta Y */functiondragCb(data){// same behavior, except different data// and you shouldn't call ss.listen(), else touchCb won't fire.}// kill scroll event listeners for an instance with ss.killScroll();// kill touch event listeners for an instance with ss.killTouch();// kill all event listeners for an instance with ss.killAll();