Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // limit scroll call for performance
- var scrollHandling = {
- allow: true,
- reallow: function() {
- scrollHandling.allow = true;
- },
- delay: 500 //(milliseconds) adjust to the highest acceptable value
- };
- // filter function for finding data-scrollto element matching class
- $.fn.filterByData = function (name, value) {
- return this.filter(function () {
- return $(this).data(name) === value;
- });
- };
- if ($('.side_nav_wrapper').length > 0) { // check for side_nav_wrapper
- $(window).on('scroll', function () {
- if(scrollHandling.allow) { // call scroll limit
- var halfWay = $(window).height() / 2; // get half height of window
- $('.sectionAnchor').each(function () { // check each section anchor
- var distance = $(this).offset().top - halfWay; // check when halfway from top
- if ($(window).scrollTop() >= distance) {
- $('.pageScroller').removeClass('active');
- var classString = $(this).attr('class');
- if (classString) {
- //Get first class from class string
- var target = classString.split(' ')[0];
- //Find anchors and filter by data-scrollto == our class name
- var navItem = $('.pageScroller').filterByData('scrollto', target);
- navItem.addClass('active');
- }
- }
- });
- } // end scorll handling limit
- }); // end window scroll
- } // end check for side_nav_wrapper
Advertisement
Add Comment
Please, Sign In to add comment