Created
September 23, 2016 07:46
-
-
Save alokstha1/473fc4dfdbcd76306071a11a9ff2feb9 to your computer and use it in GitHub Desktop.
Fixed sidebar with respect to header and footer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SCRIPT FOR PRODUCT SIDEBAR STICKY (EXPANDABLE) | |
function collision($div1, $div2) { | |
if ( $div1.length > 0 && $div2.length > 0 ) { | |
var x1 = $div1.offset().left; | |
var y1 = $div1.offset().top; | |
var h1 = $div1.outerHeight(true); | |
var w1 = $div1.outerWidth(true); | |
var b1 = y1 + h1; | |
var r1 = x1 + w1; | |
var x2 = $div2.offset().left; | |
var y2 = $div2.offset().top; | |
var h2 = $div2.outerHeight(true); | |
var w2 = $div2.outerWidth(true); | |
var b2 = y2 + h2; | |
var r2 = x2 + w2; | |
if (b1 < y2 || y1 > b2 || r1 < x2 || x1 > r2) return false; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
if ( $('body').hasClass('page-template-template-product-filter-php') || | |
$('body').hasClass('page-template-template-keep') || | |
$('body').hasClass('page-template-template-rent') || | |
$('body').hasClass('page-template-template-sell') ) { | |
$(window).scroll(function(e) { | |
var scroll_top = $(window).scrollTop(); | |
var nav_h = $('nav#cc-navbar').outerHeight(); | |
var dark_h = $('.cc-filter-dark').outerHeight(); | |
var total_h = nav_h + dark_h; | |
if ( collision( $('.navbar-fixed-top.shrink'), $('.cpm-filter-result-open form.filter-form-left') ) || scroll_top >= total_h ) { | |
$('.cpm-filter-result-open #cbp-spmenu-s1').addClass('sticky'); | |
$('.cpm-filter-result-open #cbp-spmenu-s1').css({ | |
'position': 'fixed', | |
'top' : '75px' | |
}); | |
} else { | |
$('.cpm-filter-result-open #cbp-spmenu-s1').removeClass('sticky'); | |
$('.cpm-filter-result-open #cbp-spmenu-s1').css({ | |
'position': 'static', | |
'top' : '0px' | |
}); | |
} | |
if ( collision( $('.cpm-filter-result-open #cbp-spmenu-s1'), $('footer#section-1') ) ) { | |
$('.cpm-filter-result-open #cbp-spmenu-s1').removeClass('sticky'); | |
$('.cpm-filter-result-open #cbp-spmenu-s1').css({ | |
'position': 'absolute', | |
'bottom' : '0px', | |
'top' : 'auto' | |
}); | |
} | |
}); | |
} | |
// END SCRIPT FOR PRODUCT SIDEBAR STICKY (EXPANDABLE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment