Johann-S/bs-breakpoints

Conditional

Closed this issue · 5 comments

How to use this with conditional?

Ex. if( bsBreakpoints() == "xs" ) { // do something } else { // do something }

Thanks

Hi @protasisimone,

You have to use this method: detectBreakpoint
See: https://github.com/Johann-S/bs-breakpoints#detectbreakpoint

like that:

if (bsBreakpoints.detectBreakpoint() === 'xSmall') {

Thanks for ur reply, I try this:

var header = $("#navbar");
$(window).scroll(function() {
	bsBreakpoints.init();
	var scroll = $(window).scrollTop();
	if ( bsBreakpoints.detectBreakpoint() === 'medium' ) {
		header.removeClass("navbar-dark bg-secondary").addClass("navbar-light bg-white");
	} else if ( scroll >= 195 ) {
		header.removeClass("navbar-light bg-white").addClass("fixed-top navbar-dark bg-secondary");
	} else {
		header.removeClass("fixed-top navbar-dark bg-secondary").addClass("navbar-light bg-white");
	}
});

But doesn't work.

To validate this condition:
if ( bsBreakpoints.detectBreakpoint() === 'medium' ) {

Your screen width has to be between 768px and 991px, and you have to scroll.
init should be called on document ready

I hope you find a solution @protasisimone 👍

Thanks for ur reply, have a nice day! 🙏