TheOneTrueVlad Posted January 22, 2015 Share Posted January 22, 2015 I have 3 variants of code that all do the same thing. Is there a best practice for choosing? Is it just appearance and ease of following or is there a technical reason to use one over the other? /*if ( ($(window).width() < 535) || ($(window).height() < 700) ) { if (scrollTop > stickyNavTop) { jQuery('body').addClass('stickynav'); } else { jQuery('body').removeClass('stickynav'); } } else { jQuery('body').removeClass('stickynav'); } if ( (scrollTop > stickyNavTop) && ( (($(window).height() < 700) || ($(window).width() < 535)) )) { jQuery('body').addClass('stickynav');} else { jQuery('body').removeClass('stickynav'); } if ( ((scrollTop > stickyNavTop) && ($(window).height() < 700)) || ((scrollTop > stickyNavTop) && ($(window).width() < 535)) ) { jQuery('body').addClass('stickynav');} else { jQuery('body').removeClass('stickynav'); } Cheers Link to comment Share on other sites More sharing options...
justsomeguy Posted January 22, 2015 Share Posted January 22, 2015 The second one is the most concise, it doesn't have any duplicate code. Although you don't need all of those parentheses. if ( scrollTop > stickyNavTop && ( $(window).height() < 700 || $(window).width() < 535 )) { Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now