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

  • SEARCH
  • Home
  • 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 8710689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:41:20+00:00 2026-06-13T04:41:20+00:00

I was just working around with jQuery prepend and couldn’t get it to work

  • 0

I was just working around with jQuery prepend and couldn’t get it to work as expected.

What I am doing:

Prepending a .content div to #main div every one second

But, when I scroll down a bit [once the page is full of content], I keep getting scrolled back to #main‘s top or latest prepended .content

How do I:

Prevent the viewport from changing – like in case of append

Related fiddle

  • 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-06-13T04:41:21+00:00Added an answer on June 13, 2026 at 4:41 am

    As I explained in a comment, the scroll isn’t actually changing. The window’s scroll is based on “distance from top” (DfT). That is to say that if you have no scrollbar, you’re DfT is 0. Once the scrollbars are introduced you now have a distance to work with.

    Because the content is getting longer the viewport is only so many pixels high some content “falls off” the bottom of the page (prepend is making the DfT off by the height of your new element).

    Best way I can think of is to counter it with the height of the new element. This allows you to scroll to a position then, as new elements are added, you modify the scroll position accordingly.

    Here’s an example of what I mean: http://jsfiddle.net/bradchristie/66RvC/1/

    And the code (for reference):

    var f = function(){
        var t = $(window).scrollTop(),      // Window's current scroll position
            $d = $(d()).prependTo('#main'), // store the new element
            h = $d.outerHeight();           // also get its height
        if (t){                             // Only adjust if they've scrolled
            $(window).scrollTop(t + h);     // add the delta to the scroll position
        }
        setTimeout( f, 1000 );
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a JQuery game (Just to get around with using JQuery)
I just working with JSON data and am playing around with jQuery and Ajax
I just have learnt how cool RSpec and Cabybara is, and now working around
I have the following JQuery function about a range slider . It's just working
I'm working just few days with jQuery, so question might be not very interesting.
I've just got this bit of code working in jQuery via an answer on
So I'm trying to get some basic jQuery code with Rails working, but it
I've just got a jquery function working with my rails3 application. When a user
I am having a few issues trying to get some basic jquery functionality working
Just stated to play around with Jquery and Java. I stated to setup a

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.