Sticky jQuery image not moving while scrolling

Upon visiting the mentioned website and scrolling down, you may notice that the logo image becomes stuck when transitioning between divs. This issue is likely due to my limited understanding of jQuery. The image is set as fixed using CSS and its fading effect is implemented using jQuery.

If anyone could provide assistance with this matter, it would be greatly appreciated.

<script>
        document.getElementById('listen-btn').addEventListener('click', function() {
            document.getElementById('music-player').play();
        });

    $(window).scroll(function() {
        if($(window).scrollTop() > $(document).height()*0.5)
            document.querySelector('#music-player').pause();
    });

    $(window).bind("scroll", function() {
        if ($(this).scrollTop() > $(document).height()*0.3) {
            $("#music-player").fadeIn("slow");
        } else {
            $("#music-player").fadeOut("slow");
        }
    });

    $(window).bind("scroll", function() {
        if ($(this).scrollTop() < $(document).height()*0.2) {
            $("#listen-btn").fadeIn("slow");
        } else {
            $("#listen-btn").fadeOut("slow");
        }
    });

    $(window).bind("scroll", function() {
        if ($(this).scrollTop() < $(document).height()*0.39) {
            $(".main-logo").fadeIn("slow");
        } else {
            $(".main-logo").fadeOut("slow");
        }
    });
    </script>

Answer №1

My approach would be to detach the logo div from its parent divs,

Next, I would elevate the z-index of the logo div above all other divs to ensure it is not affected by fadein and fadeout transitions

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

The jQuery function throws an Error that is not caught by the surrounding try / catch block

Recently, I've been enhancing error handling in my JavaScript objects that heavily utilize jQuery. However, I've run into an issue where throwing a new Error from within a jQuery method is not caught by the surrounding catch statement. Instead, i ...

Using Jquery's $.each() method within an ajax call can be a powerful

Is it possible for a jQuery each loop to wait for Ajax success before continuing when sending SMS to recipients from an object? I want my script to effectively send one SMS, display a success message on the DOM, and then proceed with the next recipient. O ...

Bootstrap flex: on a single row, one column spans the entire height while the other contains elements that are vertically aligned in the center

I'm having trouble with Bootstrap 4 as I try to vertically align the elements of the right column and create a full-height column on the left with just a background color. I've come across many posts discussing similar issues, but none specific t ...

How can I retrieve the iframe ID within its content using jQuery?

I am currently working on a project involving jQuery. My code looks something like this in 1.html: <html> <head> <script language="javascript" type="text/javascript" src="jquery.js"></script> </head> <body> <iframe ...

Javascript echoes are appearing in an alert rather than being processed

My registration system utilizes AJAX to process form data and return a false value. The JavaScript code snippet shown at the top handles this functionality. Upon submitting the form, the data is sent to join.php where it undergoes validation to ensure no d ...

When making a second call to .html() in JQuery, any previous calls to .css(), delay(), or fadeIn() will be ignored

Question for the Experts: Recently, I have been exploring Ajax functionality to send form data to an MVC3 controller and retrieve Json response. Upon successful submission, my goal is to: Capture the initial content of the form div using .html() Replac ...

Implementing infinite scrolling with AngularJS by dynamically incorporating images from a local folder

I have attempted multiple times but continue to struggle with adding images. My goal is to create an image gallery and implement infinite scrolling using AngularJS. Is it possible to add images from a local folder rather than a database? <body ng-app=" ...

How come the width of an element with a relative position remains maximized even when it does not have any child elements?

I am facing an issue with a "message" element that needs to be resized if the text exceeds its width within certain limits, similar to how it works in messaging applications. .message { position: relative; color: white; background: #182533 ...

What is the most straightforward method for implementing CSS transitions with fit-content for width?

Can you help me figure out how to smoothly transition the width of an element with the style attributes transition: 0.5s and width: fit-content? Specifically, I want to apply this transition to the entire element, not just the padding. Here is the Codepen ...

Steps for Loading HTML5 Video Element in Ionic 2

Struggling to showcase a list of videos from my server, here's the issue I'm encountering and the layout of the app. https://i.stack.imgur.com/HWVt3.png This is the code snippet in HTML: <ion-list> <button ion-item *ngFor="let v ...

What is the best way to delete data from a local storage using an index array?

When I log localStorage.getItem("cartCache"), the output is: {"dataCache":[{"id":20,"quantity":1,"total":100000,"request_date":"27-08-2017 20:31:00"},{"id":53,"quantity":1,"total":200000,"request_date":"27-08-2017 20:38:00"}],"expired":"2017-08-28T03:55:2 ...

The div display property in a media query

Below is the css styling for a specific div: .titleHome { position: absolute; top: 10px; left: 12px; width: 80px; height: 50px; z-index: 8; } My goal is to hide this div when the screen width exceeds 900px, and make it visible whe ...

Click and keystroke fusion

Greetings everyone, I've been attempting to integrate both click and keypress functionalities into my function, but unfortunately, nothing I've attempted so far has yielded any success. Here's the code snippet: function victoryMessage() { ...

What is the method to retrieve the return value from this ajax request?

Here's a code snippet: var information = { ObtainInfo : function() { var url = 'http://www.bungie.net/api/reach/reachapijson.svc/game/info/'+storage.get('apikey'); $.ajax({ url: url, su ...

Is it possible to utilize Dictionaries (key, value) collections with JQuery?

Is jQuery capable of supporting a collection of Dictionaries which consists of keys and values? I am interested in organizing the following data into a structured format: [1, false] [2, true] [3, false] This structure should allow for adding, looking up ...

I'm having trouble keeping items aligned on my navigation bar right after a form. Can anyone help me with this?

I'm having trouble fitting a navbar with these elements: My brand logo A lengthy search bar and submit button filling the entire height of the navbar. Space at the end of #2 for another button of equal height. ... all in one line without collapsing ...

Discover ways to retrieve an ajax response from a different domain by submitting specific data to the controller method while operating on an internet server

I am facing an issue where I am unable to retrieve array data from a Codeigniter controller using an Ajax request. The data is being posted to the controller to fetch related data from the database, and it works perfectly fine on my local server. However, ...

Misplaced SVG background images causing layout issues

I am trying to create a unique effect on an SVG image by overlaying color images on top of it through paths with background images. The goal is to make it appear as though parts of the image transition into color when hovered over. If you want to see the ...

Apply a unique style to a child element of a JavaFX LineChart

Is it possible to utilize 2 objects, each with a single line? https://i.sstatic.net/402Qp.png Currently, I have set the color like this: .chart-series-line {-fx-stroke: #ff0099; }, which changes the color of both lines. However, I need the lines to have d ...

Retrieve the hidden input's value and set it as the value of another input

There is a hidden input that I am working with: <input type="hidden" id="hidden" /> $('#hidden').before('<input type="text" id="mhidden" alt="decimal" value="" />'); var val = $('#hidden').val(); $('#mh ...