"To enhance the functionality of your website in Chrome, incorporate Bootstrap affix and

When I add a website name as a prefix, the name is initially hidden. As the user scrolls down, the website name becomes visible, and as they scroll back up, it disappears again. I have implemented this feature using jQuery.

$(document).ready(function(){
    $(window).scroll(function(){
        if (document.body.scrollTop > 50 || document.documentElement.scrollTop > 50) {
            $(".brand_name").removeClass("hidden");   
        } else {
            $(".brand_name").addClass("hidden");
        }
    });
});

Here is the code for the navigation bar:

<nav class="navbar navbar-default clearfix" data-spy="affix" data-    offset-top="197">
<div class="container-fluid">
<div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>                        
  </button>
  <a class="navbar-brand brand_name hidden" href="#">WebSiteName</a>
 </div>
 <div>
  <div class="collapse navbar-collapse" id="myNavbar">
    <ul class="nav navbar-nav">
      <li class="active"><a href="#section1">Movies</a></li>
      <li><a href="#section2">Sports</a></li>
      <li><a href="#section3">Attraction</a></li>
      <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Events <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a href="#section41">Section 4-1</a></li>
          <li><a href="#section42">Section 4-2</a></li>
        </ul>
      </li>
    </ul>
   </div>
 </div>
 </div>
 </nav>      

While this works fine in Mozilla, there seems to be a problem in Chrome. Can anyone help me with resolving this issue?

Answer №2

Utilize the code snippet below to ensure everything runs smoothly:

HTML:

<nav class="navbar navbar-default clearfix" data-spy="affix" data-offset-top="197">
<div class="container-fluid">
<div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>                        
  </button>
  <a class="navbar-brand brand_name" href="#">WebSiteName</a>
 </div>
 <div>
  <div class="collapse navbar-collapse" id="myNavbar">
    <ul class="nav navbar-nav">
      <li class="active"><a href="#section1">Movies</a></li>
      <li><a href="#section2">Sports</a></li>
      <li><a href="#section3">Attraction</a></li>
      <li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Events <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a href="#section41">Section 4-1</a></li>
          <li><a href="#section42">Section 4-2</a></li>
        </ul>
      </li>
    </ul>
   </div>
 </div>
 </div>
 </nav>    


 <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore, architecto eum sapiente dolorem nostrum saepe! Voluptas deserunt aperiam eligendi tempora sit incidunt similique ab. Sequi, earum qui blanditiis officiis magni?</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore, architecto eum sapiente dolorem nostrum saepe! Voluptas deserunt aperiam eligendi tempora sit incidunt similique ab. Sequi, earum qui blanditiis officiis magni?</p>
   <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore, architecto eum sapiente dolorem nostrum saepe! Voluptas deserunt aperiam eligendi tempora sit incidunt similique ab. Sequi, earum qui blanditiis officiis magni?</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore, architecto eum sapiente dolorem nostrum saepe! Voluptas deserunt aperiam...

JS:

var scrollvalue=$(window).scrollTop();

$(window).on("scroll", function(){
  if($(window).scrollTop()>scrollvalue)
    {
      $(".navbar-header a").removeClass('hidden');
      scrollvalue=$(window).scrollTop();
    }
  else
    {
      $(".navbar-header a").addClass('hidden');
      scrollvalue=$(window).scrollTop();
    }
});   

CSS:

.hidden{display:none;}

Check out the fiddle:

https://jsfiddle.net/SkyT/Lf1sr34y/1/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Update values of Name, Longitude, and Latitude within the Google Maps API using JQuery

I am currently working on a feature for my website where a user can select a place from a list and have its Name, Longitude, and Latitude displayed on a map for easy identification. However, I am facing an issue with updating the values on the map when th ...

Dynamic HTML gallery that supports the addition of fresh images

Looking to showcase images from a local folder in a slideshow on a simple web page? The page should automatically update when new images are added or removed from the folder. I am not an expert and prefer a minimalist design with perhaps just a transitio ...

Craft CMS contact form with an option to subscribe to our MailChimp newsletter

I'm currently working on setting up a contact form with a subscribe button in Craft CMS v2 to allow users to add their details to a MailChimp mailing list. Although I've been using the MailChimp Plugin and the Contact Form Plugin, integrating the ...

The hyperlinks in the navigation bar are leading me to incorrect destinations

I am currently developing an authentication app and facing an issue with the navbar links for register and login. They are not redirecting me to the correct destination. These links work perfectly on the landing index page, but not on any other page. site ...

Is it possible to create an HTML select that displays transparent text after a selection

I'm currently working on customizing the appearance of an HTML select element with various background color options. Everything is functioning properly, but I have a specific requirement. I want the text in the dropdown options to be visible only when ...

What are the steps to overlay a button onto an image with CSS?

As a CSS newbie, I have a question that may seem silly or straightforward to some. I am struggling with placing a button over an image and need guidance on how to achieve this effect. Specifically, I want the button to appear like this blue "Kopit" button ...

How can Jquery define a function and then utilize it as a method of a specific object?

Similar Inquiry: Understanding $.fn. in jQuery Could someone provide more insight into the code presented below? I noticed that a function named isdirty is declared. However, I am confused about: What exactly does $.fn refer to? The second line i ...

What could be the reason behind CSS internal style not working while inline style is functioning properly?

Here is the code I am currently working with. It seems that there may be an issue, but I'm not sure what it could be. The first part contains internal CSS and below is inline CSS which appears to be functioning properly. My suspicion is that the image ...

JavaScript popup cannot be shown at this time

I'm encountering an issue with displaying popups using JavaScript. Currently, only the div with class "popup" is being shown. When a user takes action, both popup and popup2 should be displayed but for some reason, it's not working as expected. ...

Tips for breaking out of an infinite loop while loading HTML containing a carousel into a blank <div> within another HTML file using jQuery's $(document).ready() function

Currently, I am studying HTML, CSS, Bootstrap 4, jQuery3, and JavaScript (ES6+), and to enhance my skills, I have devised an exercise for practice and consolidation. I have created 4 HTML files, all featuring responsive design based on Bootstrap 4: inde ...

What could be the reason that my Bootstrap dropdown menu is not appearing on my website

I am currently utilizing Angular in my project. I have incorporated bootstrap and jQuery via NPM install, and specified them as dependencies in angular.json. The navbar on my site contains a dropdown menu. When I hover over the dropdown menu, it should di ...

Is it possible to modify the cursor for disabled <button> or <a> elements in Bootstrap 4?

Is there a way to apply the cursor: not-allowed style to a button or a element? I've attempted the following: .not-allowed { pointer-events: auto! important; cursor: not-allowed! important; } Here is an example of my button: <a class=" ...

Is it possible to retrieve the decimal value from the KendonumericTextbox?

Is there a way to retrieve the decimals and format properties value? var mileagerate = $("#mileagerate").kendoNumericTextBox({ decimals: 2, format: "c2", min: 0.00, step: 0.01 }).data("kendoNumericTextBox"); I'm looki ...

Issue with horizontal scrolling functionality in DataTables

I have a table with over 10 columns, and I am using datatables to display the data. I have enabled horizontal scrolling due to the large number of columns, but the scroll is not appearing. Can someone please assist me with this issue? Here is a screenshot ...

Tips for utilizing PrependTo dynamically on every element

I am facing a requirement that involves prepending an element with a specific class to its sibling with another class. While I have managed to accomplish this for the first occurrence, it seems to fail for all other elements within the same div. Below is t ...

Can Jquery be utilized to signal a language change?

I'm working on my portfolio website that will be available in two languages, Thai and English. I have successfully implemented language buttons for changing between the two languages. However, I am facing an issue with the language selection when nav ...

Turbolinks gem causing ShareThis to malfunction

After adding the turbolinks and jquery-turbolinks gems to my project, I noticed that my ShareThis button no longer pops up when clicked. The ShareThis scripts currently included in my application.html.erb head are: <script type="text/javascript">va ...

insert a div element at a static position with a height of 100%

Adding two divs on top and bottom of a fixed div is what I need to do. To achieve this, I created a panel with a fixed position on the left side. I added the first div with the h-100 class which sets its height to 100%. However, when I try to add the secon ...

Enhancing a Form Submission with Ajax

Working on a complicated form generated with Symfony2 and rendered using Twig and JQuery. This form is utilized to make modifications to e-commerce orders, therefore there's no clear submission process. How do I effectively sync the old form with the ...

What is the best way to ensure my buttons hide or display correctly when clicked?

I have been working on setting up an edit button that toggles the visibility of save and cancel buttons. However, I encountered a problem where all the buttons disappear when I click on the edit button. This issue did not occur with my other buttons, and t ...