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"); } } }); 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
Post a Comment