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 8079909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:15:38+00:00 2026-06-05T16:15:38+00:00

I am trying to have a content block always be shown to the user,

  • 0

I am trying to have a content block always be shown to the user, even if he scrolls way down the page. He should also be able to scroll up and down the content block. Here is a fiddle with a stripped down version to show you what I mean:

http://jsfiddle.net/9ehfV/2/

One should notice when scrolling down, until reaching the bottom of the red block, it will fix the block on the window, and when scrolling back up, it places it back.

In Firefox one can scroll up and down and the fixing/unfixing described above is imperceptible – smooth as silk.

Once one tries scrolling in Chrome or IE, though, it seems like the scroll event lags and one can see the block “glitching” for a second. It’s not code lag – it seems to be something with the browsers.

Is there any way to fix this? I’m at my wit’s end.

I’d appreciate suggestions on how I can achieve the same effect in a different way…thanks

  • 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-05T16:15:39+00:00Added an answer on June 5, 2026 at 4:15 pm

    Since JavaScript runs in the same thread as the UI, a scroll event callback can block the UI-thread and thus cause lag. You need to throttle the scroll event listener because some browsers fire a lot of them. Especially if you’re on OS X with an analog scroll device. Since you do a lot of height calculations in your listener, it will trigger a reflow (very expensive) for every scroll event that is fired.

    To throttle the listener, you have to prevent the listener from firing every time. Usually you wait until the browser doesn’t trigger an event for x milliseconds, or have a minimum time between calling your callback. Try adjusting the value to see the effect. Even 0 milliseconds can help, since it will delay the execution of the callback until the browser has time (usually 5-40 ms).

    It’s also a good practice to toggle a class to switch between states (static and fixed position) instead of hard-coding it in JavaScript. Then you have a cleaner separation of concerns and avoid potential extra redraws by mistake (see “Browsers are smart” section). (example on jsfiddle)

    Wait for a pause of x ms

    // return a throttled function
    function waitForPause(ms, callback) {
        var timer;
    
        return function() {
            var self = this, args = arguments;
            clearTimeout(timer);
            timer = setTimeout(function() {
                callback.apply(self, args);
            }, ms);
        };
    }
    
    this.start = function() {
        // wrap around your callback
        $window.scroll( waitForPause( 30, self.worker ) );
    };
    

    Wait at least x ms (jsfiddle)

    function throttle(ms, callback) {
        var timer, lastCall=0;
    
        return function() {
            var now = new Date().getTime(),
                diff = now - lastCall;
            console.log(diff, now, lastCall);
            if (diff >= ms) {
                console.log("Call callback!");
                lastCall = now;
                callback.apply(this, arguments);
            }
        };
    }
    
    this.start = function() {
        // wrap around your callback
        $window.scroll(throttle(30, self.worker));
    };
    

    jQuery Waypoints
    Since you’re already using jQuery, I would have a look at the jQuery Waypoints plugin which has a simple and elegant solution to your problem. Just define a callback when the user scrolls to a certain waypoint.

    Example: (jsfiddle)

    $(document).ready(function() {
        // throttling is built in, just define ms
        $.waypoints.settings.scrollThrottle = 30;
    
        $('#content').waypoint(function(event, direction) {
            $(this).toggleClass('sticky', direction === "down");
            event.stopPropagation();
        }, {
            offset: 'bottom-in-view' // checkpoint at bottom of #content
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure out how to read paragraph content which exists
I am trying to get file content in bytes in Android application. I have
I have a swf that requires flash 9, and I'm trying to show content
I have an XML file as follows, and I'm trying to read the content
I'm trying to teach myself CSS and have the following markup: <style type=text/css> #content
I am trying to have a simple block of JS code call my Silverlight
I have inserted content using the :before pseudo-element for a class. I was trying
I have had a road-block that has cascaded itself down to the situation described
I have 4 content placeholder from my master page and I am using the
I am trying to rerun a block of javascript when the user clicks on

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.