Jump to content

Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...