Screen jumping occurs when the jQuery fadeOut effect is triggered by scrolling

I’m currently working on a website where I have a fullscreen .intro DIV. When clicking on .down, the page smoothly scrolls to the main content and the .intro div fades out.

Everything seems to be functioning correctly, except that after the .intro fades out, the page suddenly shifts downward, forcing the user to scroll back up. This is not an ideal user experience.

I’ve been unable to identify the cause of this issue. You can view a working example in my JSFiddle. In the JSFiddle, I've included a gradient background so you can see the page jumping down after the 1500 milliseconds it takes for .intro to fadeOut.

Below is the jQuery code I am using:

(function($) {
jQuery(document).ready(function($) {
    $(".scroll").click(function(event){ 
        event.preventDefault(); 
        $('html,body').animate({scrollTop:$(this.hash).offset().top}, 1000); 
    });
});
})(jQuery);

$(".down").click(function() { 
$(".intro").fadeOut(1500);
});

Answer №1

fadeAway() gradually makes the element disappear by adjusting its opacity, followed by setting the display property to none. This action removes the element from the document flow, resulting in a noticeable jump on the page.

To prevent this jumping effect, consider using either vanishTo() or animating the opacity of the element while keeping it in place. However, keep in mind that even when not visible, the element will still occupy space.

$(".up").click(function() { 
    $(".intro").vanishTo(0);
});

Alternatively, you can utilize the callback function of the fadeAway() method to reset the scrollTop position, creating an illusion that the page hasn't shifted. Note that this may result in some flickering on certain browsers:

$(".intro").fadeAway(1500, function() {
    $(window).scrollTop(0)
});

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 toFixed() function seems to only be giving back values ending in

The issue I'm facing is that the code below is only returning decimal places with values like .00, even when the set values are supposed to be .67, 1.33, 2.67, etc. $(function($) { $('#CourseMenu select').change(function() { var ...

The unique GopikaTwo Gujarati font is unfortunately not compatible with Android mobile browsers and hybrid applications

I am currently trying to incorporate the custom font GopikaTwo into my hybrid application. Below is the code snippet I have added to my CSS file: @font-face { font-family: 'GopikaTwo' !important; src: url('GopikaTwo.eot') !impo ...

Having trouble retrieving data from an external nested JSON file using jQuery

I'm attempting to retrieve data from an external nested JSON file using AJAX. Here is my AJAX call: <script> var json1 = (function () { var json1 = null; $.ajax({ 'async': false, 'global': false, 'url&a ...

Using JQuery Datatable plugin to bind data in ASP.NET MVC applications

Having trouble implementing the JQuery Datatable plugin in my ASP.NET MVC application. Despite receiving JSON data from the controller, the table is stuck displaying a "Loading..." message. Here is my controller code: public ActionResult GetCompanies(jQu ...

The append function in jQuery is malfunctioning on the website

Hello, I am trying to append a form from Bootstrap using the jQuery append function. However, instead of opening once, it opens twice. Additionally, the button at the end of the form only shows up sometimes and hides other times. I want the form to show on ...

JavaScript and jQuery radio button matrix group implementation

I'm feeling completely lost when it comes to solving this problem. My task is to create a matrix of radio buttons with columns labeled 1 to 3 and rows labeled A to C. A B C 1 (o) (o) (o) 2 (o) (o) (o) 3 (o) (o) (o) <tabl ...

Contains a D3 (version 3.4) edge bundle chart along with a convenient update button for loading fresh datasets

I am looking to update my D3 (v3.4) edge bundling chart with a new dataset when a user clicks an 'update' button. Specifically, I want the chart to display data from the data2.json file instead of data1.json. Although I have started creating an u ...

Can the jQuery picker control be utilized again even if there are validation errors?

I am having an issue with my datetime picker in ASP.NET MVC using Razor. When the form is submitted and there is a validation error message, my entered values are not retained and the picker stops working. Is there a way to reuse the picker control after a ...

How can I dynamically update an input field within a Bootstrap modal only if the field is not already filled?

I am facing an issue with my dynamic table form. After filling out the form, I want the values from all fields to be inserted into one field with commas separating them. However, I am unsure of how to check if a field is empty and insert data, or update da ...

Having trouble displaying a dynamically created table using jQuery

I'm a newcomer to jQuery and I need help with querying 2 web services. The goal is to query the first service, use an attribute value to query the second one, and then populate a table with data from both services. Please take a look at my code on th ...

Internet Explorer failing to trigger Ajax requests

I'm encountering an issue with my script on my webpage - it works perfectly in Chrome, but Internet Explorer is not entering the success{} function of Ajax. It does go into the Complete{} function without any problems. I attempted to pass the data var ...

The compatibility issue between Bootstrap4 Navbar and "jQuery.BgSwitcher" is causing functionality limitations on mobile devices

Currently, I am utilizing Bootswatch4 within Bootstrap4 and have a requirement for a div with backgrounds that change or fade. After some research, I stumbled upon a JavaScript solution that aligns closely with my needs at: https://github.com/rewish/jquery ...

What is the process for daily web scraping of news articles using Python?

As I work on developing an application, I require daily news feeds from multiple websites. Utilizing Python's BeautifulSoup library seems like a viable option, but it may not be suitable for websites that display news across various pages which requir ...

"Unlocking the potential of JSON: A guide to retrieving and displaying three specific fields in

My PHP service is returning the following data: [[1,"16846"],[2,"16858"],[3,"16923"],[4,"16891"]] Within my HTML, I have ajax set up to fetch this information; $.ajax({ type: 'POST', url: 'getDadosGrafico.php', ...

What is the best method for transferring file information using Dajaxice?

I have integrated ajax functionality into my website and have successfully utilized jQuery.ajax() to asynchronously upload files to the server. In addition, I am incorporating Dajax and Dajaxice into my application for file uploads as well. To achieve this ...

Creating nested tabs with Bootstrap: A step-by-step guide on adding tabs within tabs

I am encountering a challenge with nested tabs. I am utilizing Bootstrap and not using custom CSS. Any assistance would be greatly appreciated. <div class="container-fluid"> <!-- Tabs --> <ul class="nav nav-t ...

Display or conceal the nearest element that was clicked

http://jsfiddle.net/KevinOrin/xycCx/1/ jQuery('.happening-main-text .readmore').click(function() { jQuery('.divmore').toggle('slow'); return false; }); ...

Looking for a Horizontal Layout?

@foreach (var item in APModel) { <div class="row row-cols-1 row-cols-md-2 g-4"> <div class="col"> <div class="card" style="width: 18rem;"> <img src="h ...

Clicking on the icon image that features a Background Video will trigger the video to play in a popup window originating from the same location

A background video is currently playing on the site. When the play icon is clicked, the video should start playing in a popup. The video should start playing continuously from the exact moment and position where it is clicked. Check out the example here. ...

Introducing whitespace nowrap disrupts the CSS grid layout

I've encountered an issue with a grid layout featuring 2 columns. I'm trying to insert an element into one of the columns that will display an ellipsis if its content is too long. However, when I add whitespace: nowrap; to the CSS, it causes the ...