Sign inSign up

jQuery Automatic Vertical Full-Page Scrolling Navigation Plugin section-scroll.js

Add-ons
2026-07-25 23:04 4 views • 0 downloads 88.4KB
jQuery Automatic Vertical Full-Page Scrolling Navigation Plugin section-scroll.js

section-scroll.js

A jQuery plugin for automatically generating navigation for scrollable sections.


Usage

Download the compressed package and include jquery, jquery.section-scroll.js, and section-scroll.css in your page. If you need animated transitions with easing effects, you can also include jquery.easing.1.3.js.

1
2
3
4
<link href="css/section-scroll.css" rel="stylesheet" />
<script src="js/jquery.min.js"></script>
<script src="js/jquery.easing.1.3.js"></script>
<script src="js/jquery.section-scroll.js"></script>

HTML Structure

This plugin treats each <section> element as a separate section, with each scrolling navigation button corresponding to one section.

1
2
3
<div class="scrollable-section" data-section-title="Section-1"></div>
<div class="scrollable-section" data-section-title="Section-2"></div>
<div class="scrollable-section" data-section-title="Section-3"></div>

Here, scrollable-section is the <section> you want to include in the scrolling navigation. The plugin uses the data-section-title attribute as the title of the navigation menu item.

Initialize the Plugin

After the page DOM elements have finished loading, initialize the section-scroll.js plugin using the following method.

1
2
3
4
5
<script type="text/javascript">
$(document).ready(function () {
$('body').sectionScroll();
})
</script>

Configuration Parameters

The default configuration parameters of the section-scroll.js plugin are:

1
2
3
4
5
6
bulletsClass: 'section-bullets',
sectionsClass: 'scrollable-section',
scrollDuration: 1000,
titles: true,
topOffset: 0,
easing: ''
ParametersTypeDescription
bulletsClassstringSet the class for the dot navigation menu.
sectionsClassstringBy default, the plugin looks for elements with the classscrollable-section's<section>as scrollable sections. You can change this class using this parameter.
scrollDurationintDuration of the transition when scrolling from one section to another.
titlesbooleanSet to false to hide titles in the navigation.
topOffsetintFor example, setting this value to 100 means that when scrolling to a section, the section will be positioned 100 pixels from the top of the page.
easingstringBy default, this plugin does not provide easing effects. You can includehttp://gsgd.co.uk/sandbox/jquery/easing/after the plugin and use this parameter to configure easing effects. Available easing values can be found inhttp://easings.net/

Events

section-reached: This event is triggered whenever a section scrolls into the viewport.

1
2
3
$('body').on('section-reached', function(){
console.log('section-reached');
})

Tips

You can also access the active section through the activeSection variable. For example:

1
2
3
4
$('body').on('section-reached', function(){
var section_title = $('body').sectionScroll.activeSection.data('section-title');
alert(section_title);
})

See the following example:

1
<section class="scrollable-section" data-short-description="We love coding"></section>

Now we can retrieve the section title and display it in a div.

1
2
3
4
5
6
$('body').on('section-reached', function(){
var short_description = $('.body').sectionScroll.activeSection.data('short-description');
$('div').html(short_description);
// We can also change the background color of the active section.
$('body').sectionScroll.activeSection.css('background-color', '#000');
})