conditions for adjusting padding fixed

This commit is contained in:
ARvind Tiwari 2017-08-09 01:32:41 +05:30
parent 7bde3149f5
commit 789946ff77

View file

@ -42,15 +42,25 @@ function getScrollbarWidth() {
// globally stores the width of scrollbar // globally stores the width of scrollbar
var scrollbarWidth = getScrollbarWidth(); var scrollbarWidth = getScrollbarWidth();
var paddingAdjusted = false;
$( document ).ready(function() {
// add proper padding to fixed topnav on modal show // add proper padding to fixed topnav on modal show
$('body').on('click', '[data-toggle=modal]', function(){ $('body').on('click', '[data-toggle=modal]', function(){
var $body = $('body');
if ($body[0].scrollHeight > $body.height()) {
scrollbarWidth = getScrollbarWidth();
var topnavPadding = parseInt($('.navbar-fixed-top.topnav').css('padding-right')); var topnavPadding = parseInt($('.navbar-fixed-top.topnav').css('padding-right'));
$('.navbar-fixed-top.topnav').css('padding-right', topnavPadding+scrollbarWidth); $('.navbar-fixed-top.topnav').css('padding-right', topnavPadding+scrollbarWidth);
paddingAdjusted = true;
}
}); });
// remove added padding on modal hide // remove added padding on modal hide
$('body').on('hidden.bs.modal', function(){ $('body').on('hidden.bs.modal', function(){
if (paddingAdjusted) {
var topnavPadding = parseInt($('.navbar-fixed-top.topnav').css('padding-right')); var topnavPadding = parseInt($('.navbar-fixed-top.topnav').css('padding-right'));
$('.navbar-fixed-top.topnav').css('padding-right', topnavPadding-scrollbarWidth); $('.navbar-fixed-top.topnav').css('padding-right', topnavPadding-scrollbarWidth);
}
});
}); });