The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

No navbr on Mobile Version?

2 posters

Go down

Solved No navbr on Mobile Version?

Post by Mati October 6th 2023, 1:37 pm

I'm using this code to make the navbar sticky but there is a problem when you view the forum on mobile version there is no menu from mobile version, so you can't use the web version from the mobile itself?

My forum https://forumservice.forumotion.com/

Code:
$(document).ready(function(){
  var num = $(".navbar").offset().top;
  $(window).bind('scroll', function() {
    if ($(window).scrollTop() > num) { 
      $('.navbar').addClass('sticky'); 
    }
    else { 
    $('.navbar').removeClass('sticky');   
    }
  });
});


Last edited by Mati on October 6th 2023, 2:14 pm; edited 1 time in total
Mati
Mati
Active Poster

Posts : 1925
Reputation : 331
Language : HTML, CSS & JavaScript
Location : Forum Services

https://forumservice.forumotion.com/

Back to top Go down

Solved Re: No navbr on Mobile Version?

Post by Razor12345 October 6th 2023, 1:49 pm

Good afternoon!

You can add a check for the user's screen width. If more than 900px (tablets can be this wide) - the code works.

Code:
$(document).ready(function(){
  const widthOfScreen = window.innerWidth;
  if (widthOfScreen > 900) {
  var num = $(".navbar").offset().top;
  $(window).bind('scroll', function() {
    if ($(window).scrollTop() > num) {
      $('.navbar').addClass('sticky');
    }
    else {
    $('.navbar').removeClass('sticky'); 
    }
  });
}
});



No navbr on Mobile Version? Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1541
Reputation : 266
Language : Ukr, Rus, Eng
Location : Ukraine

Mati likes this post

Back to top Go down

Solved Re: No navbr on Mobile Version?

Post by Mati October 6th 2023, 2:12 pm

Lovely thanks for the help and quick reply Smile
Mati
Mati
Active Poster

Posts : 1925
Reputation : 331
Language : HTML, CSS & JavaScript
Location : Forum Services

https://forumservice.forumotion.com/

Back to top Go down

Solved Re: No navbr on Mobile Version?

Post by Razor12345 October 6th 2023, 2:26 pm

You are welcome!

Problem solved & topic archived.
Please read our forum rules: ESF General Rules


No navbr on Mobile Version? Screen51
Razor12345
Razor12345
Support Moderator
Support Moderator

Male Posts : 1541
Reputation : 266
Language : Ukr, Rus, Eng
Location : Ukraine

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum