Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:14:14+00:00 2026-05-31T22:14:14+00:00

This is my code for resizing the window and some other elements and in

  • 0

This is my code for resizing the window and some other elements and in the scroll function. I have a div that appears and disappears in different position of the screen depending on the x.top of the window.

The problem on the scroll function when I go to hidden_div2 the text inside the <p> fades in. My problem is when you come back to first div the text fades in and out 6 times. HELP 🙁

var image_position = new Array();
var i = 0;

function imageResize() {
    $('.images').find('img').each( function (){
        var dwidth = $(window).width();
        var dheight = $(window).height();
        
        var imagewidth = $(this).attr('width');
        var imageheight = $(this).attr('height');
        var imageratio = imagewidth / imageheight;
        
        var imagehresize = dwidth;
        var imagevresize = imagehresize * imageratio;
        
        var x = $(this).parent('div').position();
        image_position[i] = x.top;
    
        var boxleft = dwidth / 6;

        i++;
    });
    
}

$(window).scroll(function(){
    var x = $('.hidden_div').offset();
    var img1 = image_position[2];
    var img2 = image_position[3];
    
    if(x.top > img1){
        $('.hidden_div').css('z-index', '40');
        $('.hidden_div p').fadeOut(2000);
        $('.hidden_div2').css('z-index', '130');
        $('.hidden_div2 p').fadeIn(2000);

    }
    else if(x.top < img1){
        $('.hidden_div').css('z-index', '130');
        $('.hidden_div p').fadeIn(2000);
        $('.hidden_div2').css('z-index', '40');
        $('.hidden_div2 p').fadeOut(2000);
    }

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:14:16+00:00Added an answer on May 31, 2026 at 10:14 pm

    The scroll event is generated one or more times as the user scrolls. It is NOT only generated once for each overall user scroll. It may be generated many times. Thus, you are seeing more than one scroll event.

    If you want to carry out an action AFTER the user appears to be done with a scrolling operation, then you will have to debounce the scroll event so that you only start your operation after a scroll event occurs and no more scroll events occur for some period of time (often 1-2 seconds).

    In your code, that debouncing can be done like this:

    var scrollTimer;
    $(window).scroll(function() {
        // if we had a scrollTimer running, stop it
        if (scrollTimer) {
            clearTimeout(scrollTimer);
        }
        // set a new scrollTimer
        scrollTimer = setTimeout(function() {
            scrollTimer = null;
            processScroll();
        }, 1000);   // wait for 1 second of no-scroll events before firing our changes
    });
    
    function processScroll() {
        var x = $('.hidden_div').offset();
        var img1 = image_position[2];
        var img2 = image_position[3];
    
        if(x.top > img1){
            $('.hidden_div').css('z-index', '40');
            $('.hidden_div p').fadeOut(2000);
            $('.hidden_div2').css('z-index', '130');
            $('.hidden_div2 p').fadeIn(2000);
    
        }
        else if(x.top < img1){
            $('.hidden_div').css('z-index', '130');
            $('.hidden_div p').fadeIn(2000);
            $('.hidden_div2').css('z-index', '40');
            $('.hidden_div2 p').fadeOut(2000);
        }
    
    }
    

    If you don’t want the debouncing, then perhaps you can just stop the previous animation like this:

    $(window).scroll(function(){
        var x = $('.hidden_div').offset();
        var img1 = image_position[2];
        var img2 = image_position[3];
    
        if(x.top > img1){
            $('.hidden_div').css('z-index', '40');
            $('.hidden_div p').stop(true).fadeOut(2000);
            $('.hidden_div2').css('z-index', '130');
            $('.hidden_div2 p').stop(true).fadeIn(2000);
    
        }
        else if(x.top < img1){
            $('.hidden_div').css('z-index', '130');
            $('.hidden_div p').stop(true).fadeIn(2000);
            $('.hidden_div2').css('z-index', '40');
            $('.hidden_div2 p').stop(true).fadeOut(2000);
        }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this open-source library that I'm having some trouble fixing a problem... This
I have been pulling my hair out trying to do some dynamic div resizing
This code attempts to dynamically switch the class of the StateContainer div from StateOne
This code: $(#permalink a).click(function(id){ var id = this.getAttribute('href'); $(#newPostContent).load(id, function() { $(#removeTrigger).click(function() { $(#removeThis).hideToggle();
Please see this jsFiddle for reference: (jsFiddle) Div Resizing [to see what I'm having
For the problematic behavior, try resizing the window of this web app. Thought the
I discovered this while doing some programmatic panel resizing: Components in a spark Panel
Having a bit of an issue please see the following code: window.onload = function
This Code: Something = new Guid() is returning: 00000000-0000-0000-0000-000000000000 all the time and I
This code gives me an empty result. I expect it to print out the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.