All Projects → d4nyll → Smartscroll

d4nyll / Smartscroll

Licence: mit
jQuery plugin for scrolljacking and auto-hashing

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Smartscroll

jquery-asColorPicker
ColorInput is a jQuery plugin used to show color picker for a input field.
Stars: ✭ 18 (-92.94%)
Mutual labels:  jquery-plugin
Github-Contribution-Graph
Jquery plugin to render like contribution graph on Github.
Stars: ✭ 43 (-83.14%)
Mutual labels:  jquery-plugin
Web-Time-Tracker
Plugin named Timetracker is a time counter that works in both increase and decrease directions.
Stars: ✭ 21 (-91.76%)
Mutual labels:  jquery-plugin
LineProgressbar
A light weight jquery progressbar plugin
Stars: ✭ 34 (-86.67%)
Mutual labels:  jquery-plugin
jQuery-plugins
jQuery-plugins
Stars: ✭ 36 (-85.88%)
Mutual labels:  jquery-plugin
image-uploader
Simple Drag & Drop image uploader plugin to static forms, without using AJAX
Stars: ✭ 70 (-72.55%)
Mutual labels:  jquery-plugin
bootstrap-dropselect
A simple jQuery plugin that extends bootstrap's dropdown menu into something like github's select menu.
Stars: ✭ 77 (-69.8%)
Mutual labels:  jquery-plugin
scrupulous
Simple inline form validation using HTML5 attributes that plays nicely with Bootstrap
Stars: ✭ 12 (-95.29%)
Mutual labels:  jquery-plugin
jquery-steps
✅ Lightweight jQuery step wizard plugin.
Stars: ✭ 93 (-63.53%)
Mutual labels:  jquery-plugin
jquery.simple-scroll-follow
jQuery plugin to move the element according to the scrolling window.
Stars: ✭ 34 (-86.67%)
Mutual labels:  jquery-plugin
jquery.random-fade-in
jQuery plugin to fade-in at random.
Stars: ✭ 13 (-94.9%)
Mutual labels:  jquery-plugin
jquery-xhr-upload-queue
📂 A jQuery queued file uploading plugin.
Stars: ✭ 17 (-93.33%)
Mutual labels:  jquery-plugin
personJudge
personJudge System 网站预览---->http://47.106.235.227 (账号111,密码12345) 后端:SpringBoot/JPA/mysql/cache/前后端分离(nginx做静态转发)/swagger 前端:bootstrap+Jquery及其插件:jquery-cookie,toastr,steps,validate,wnumb,nouislider,DataTables,layer,chosen,echarts
Stars: ✭ 35 (-86.27%)
Mutual labels:  jquery-plugin
jquery-microdata
jQuery plugin for HTML Microdata
Stars: ✭ 13 (-94.9%)
Mutual labels:  jquery-plugin
MeeInk
Material Design click effect
Stars: ✭ 33 (-87.06%)
Mutual labels:  jquery-plugin
jquery.skeleton.loader
A jQuery plugin to make screen skeleton loader.
Stars: ✭ 65 (-74.51%)
Mutual labels:  jquery-plugin
leaflet-locationpicker
Simple location picker on Leaflet map
Stars: ✭ 31 (-87.84%)
Mutual labels:  jquery-plugin
Jquery Tablesort
A tiny & dead-simple jQuery plugin for sortable tables.
Stars: ✭ 254 (-0.39%)
Mutual labels:  jquery-plugin
jquery-skeduler
This is jQuery plugin which provides you simple scheduler with some items on OX and 24-hours timeline on OY.
Stars: ✭ 23 (-90.98%)
Mutual labels:  jquery-plugin
menu
基于jQuery的轻量级响应式菜单插件
Stars: ✭ 18 (-92.94%)
Mutual labels:  jquery-plugin

smartscroll

FOSSA Status

smartscroll is a tiny (1815b minfied + gzipped) jQuery plugin that has these independent features:

  1. Section scrolling - Scrolljacking
  2. Auto-hash - Updates the URL hash based on current position on page
  3. Responsive - You can disable scrolljacking below a set breakpoint

It also supports:

  1. Varied Section Heights
  2. Hybrid Scrolling - Both normal and scrolljacking on the same page
  3. Compatible with scrollbar - Can use scrollbar as well as mousewheel
  4. Disabling permalink history
  5. Correctly detects scroll events for inertial scrolling, by integrating with lethargy as a soft dependency (which means it will work without it)
  6. Provides events you can listen to, by integrating with EventEmitter as a soft dependency

Demo

Requirements

  1. There can only be one set of adjoining sections

How to Use

Install lethargy, which is available as a Bower package, which you can install with bower install.

Structure your HTML like so (default options included)

<body>
  <div class="section-wrapper">
    <div class="section" data-hash="section-hash-name"></div>
    <div class="section" data-hash="section-hash-name"></div>
  </div>
<script src="path/to/lethargy.min.js">
<script src="https://rawgit.com/Olical/EventEmitter/master/EventEmitter.min.js"></script>
<script src="path/to/smartscroll.min.js">
<script>
  var options = {
    mode: "vp", // "vp", "set"
    autoHash: false,
    sectionScroll: true,
    initialScroll: true,
    keepHistory: false,
    sectionWrapperSelector: ".section-wrapper",
    sectionClass: "section",
    animationSpeed: 300,
    headerHash: "header",
    breakpoint: null,
    eventEmitter: null,
    dynamicHeight: false
  };
  $.smartscroll(options);
</script>
</body>

You may also want to link to styles.css, but all that does is to ensure the html and body elements have no margins nor padding

You may also leave out lethargy, but smartscroll may not work as well with scroll devices that uses inertial scrolling. Performance with lethargy can be slower, but it will be improved with further development.

Options
  • mode - (String) Valid options are:
    • vp (Viewport) - The sections will be automatically sized to be the same as the viewport
    • set - Use the height and width set by CSS (use this for having different heights for different sections)
  • autoHash - (Boolean) Whether the auto-hashing feature is enabled. If you use this feature, it is important to use EventEmitter as well, otherwise smartscroll will listen to every scroll event, which is very resource-draining and can make the animation more 'glitchy'
  • sectionScroll - (Boolean) Whether the section-scrolling feature is enabled
  • initialScroll - (Boolean) Whether smartscroll should scroll to the position specified by the hash on initial load
  • keepHistory - (Boolean) Whether scrolling through different sections will be recorded in the browser's history
  • sectionWrapperSelector - (String) The CSS selector for the block element which wraps around your sections
  • sectionClass - (String) The class name applied to each section
  • animationSpeed - (Integer) Time taken for the scroll animation, in miliseconds
  • headerHash - (String) The hash for the section above the sections, must be non-empty to reliably ensure the page do not jump when updating the hash value across browsers (as # means _top)
  • breakpoint - (Integer) The width of the browser below which scrolljacking will be disabled
  • sectionSelector - (String) The selector applied to each section, overrides sectionClass and allow more flexibility in choosing a selector. (Added in 2.1.0)
  • dynamicHeight - (Boolean) If you are going to be dynamically adding and removing content so as to change the position and/or size of the section wrappers and/or sections, then set this to true. Set to false otherwise to increase performance.
  • eventEmitter - (Object) If you pass in an EventEmitter object, autoHashing will be much more efficient. You can also listen to the scroll events this way. Defaults to null.
  • ie8 - If you need to support Internet Explorer 8, change this to true. Defaults to false.
  • bindSwipe - (Boolean) Allow for listening of swipe events. Requires EventEmitter. Defaults to true
  • bindKeyboard - (Boolean) Allow for keyboard events (up and down arrows) to control slides. Defaults to true

Events

Smartscroll has a soft dependency on EventEmitter. If present, smartscroll can provide six events scrollStart, scrollEnd, swipeLeft, swipeRight, swipeDown and swipeUp. The scrollStart and scrollEnd listener will receive the slide number as its only argument; the first slide will have a number of 1, the section before the sectionWrapper will have a number of 0.

var ee = new EventEmitter();
var scrollStartListener = function (slideNumber) {
  console.log("Scrolling to " + slideNumber);
}
var scrollEndListener = function () {
  console.log("Scrolling End");
}
ee.addListener('scrollStart', scrollStartListener);
ee.addListener('scrollEnd', scrollEndListener);
$.smartscroll({
  ...
  eventEmitter: ee
});

The other listeners receive no arguments.

var ee = new EventEmitter();
var swipeUpListener = function () {
  console.log("Swiping Up");
}
var swipeDownListener = function () {
  console.log("Swiping Down");
}
$.smartscroll({
  ...
  eventEmitter: ee,
  bindSwipe: true
});
ee.addListener('swipeUp', swipeUpListener);
ee.addListener('swipeDown', swipeDownListener);

Manual Scroll

You can manually scroll up or scroll down.

When you first initiate smartscroll with $.smartscroll(), it returns an object. In that object is the scroll function, which is called with a single parameter. If the parameter is truthy, it will scroll down, otherwise, it will scroll up.

var smartscroll = $.smartscroll();
smartscroll.scroll(1);

Architecture

Currently, there are two features of smartscroll, and this is how it's implemented:

  1. Smooth scroll by section

The mousewheel and DOMMouseScroll (for Firefox) events are bound.

When such event is fired in vp mode, smartscroll will find it's most prominent section (one which occupies most of the screen), and smoothly scroll to the section above or below it.

When the event is fired in set mode, smartscroll will find which section occupies the middle of the screen, and smoothly scroll to the section above or below it.

When scrolling outside of the sections, normal scrolling resumes.

  1. Changing URL hash based on the current section

The scroll event is bound.

When the event is fired in vp mode, smartscroll will see which section occupies the top of the viewport, and if the hash is different, replace it with the new one.

When the event is fired in set mode, smartscroll will see which section occupies the middle of the viewport, and if the hash is different, replace it with the new one.

License

FOSSA Status

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].