javascript - Fullpage.js - Setting value for 'setFitToSection' option based on if a div has a certain class -


i have code partially written not sure put after if , else parts. i'm trying - whenever section has class "four" , "active" want disable fittosection option fullpage.js. fullpage.js has built in setfittosection boolean i'm using. have far, else need?

$(document).ready(function () {     if ($('.four').hasclass('active') === true) {         $.fn.fullpage.setfittosection(false);     }      else {         $.fn.fullpage.setfittosection(true);     } }); 

just use callbacks fullpage.js provides, such afterload or onleave:

$('#fullpage').fullpage({     autoscrolling:false,      onleave: function(index, nextindex, direction) {         var destination = $('.fp-section').eq(nextindex - 1);          if(destination.hasclass('four')){            $.fn.fullpage.setfittosection(false);            console.log("setting fittosection off");         }else{             $.fn.fullpage.setfittosection(true);             console.log("setting fittosection on");         }     } }); 

example online

you don't need check active class in case because destination section have it. check if has four class.

a shorter version of same script can be:

$('#fullpage').fullpage({     autoscrolling:false,      onleave: function(index, nextindex, direction) {         var destination = $('.fp-section').eq(nextindex - 1);         $.fn.fullpage.setfittosection(!destination.hasclass('four'));     } }); 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -