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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:58:27+00:00 2026-06-14T05:58:27+00:00

What is the right way to build simple floating div s using Javascript (or

  • 0

What is the right way to build simple floating divs using Javascript (or CSS programmatically)
that is on top and always visible when scrolling down?

Now I’ve seen examples like this. When you scroll down you see the div jumping and a delay. I want it to constantly be on top when the content of the page is not my ,
the script will be injected via chrome extention

can it be done?
something like this ; but less complex and not depend on the page content

  • 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-14T05:58:28+00:00Added an answer on June 14, 2026 at 5:58 am

    With the class or id of the element you want to keep on top you should apply some CSS rules,

    for example, if your element class is .topnavigation

    you could do the following in jQuery

    <style>
    .topnavigation {
        width:;/* add the width here */
        position:static;
    }
    .topnavigation.scrolling {
        position:fixed;
        top:0px;
    }
    </style>
    <script>
    $(window).scroll(function () { 
        if($(this).scrollTop() > 50) // change 50 to what you want (work out how far the nav is from the top of the page alraedy and add it there, that'll make it smoother transition)
        {
            $('.topnavigation').addClass('scrolling');
        } else {
            $('.topnavigation').removeClass('scrolling');
        }
    });
    </script>
    

    If you can’t use jQuery you could do the following with normal javascript:

    Updated: 06 Jan 2017
    I’ve updated this to use the document.querySelector and Element.classList methods. All modern browsers and IE 10 > support these methods.

    window.addEventListener('scroll',checkPosition,false);
    function checkPosition()
    {
        // #theid or #theclass or standard element selector
        var xNAV = document.querySelector("#topnav"); 
        if(window.scrollY > 50)
        {
            xNAV.classList.add("scrolling");
        } else {
            xNAV.classList.remove("scrolling");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble trying to find the right way to use MSBuild to build
Which is the right way of declaring a global javascript variable? The way I'm
Simple Question ;) Is there a way to simply install the package using pip
Hey, so I'm trying to build a simple lan game using sockets (not tcpclient
I'm trying to build a simple Node app using Express, Socket.io, and the ntwitter
I want to build a simple code generator in java that can take database
So, I practiced HTML/CSS, and wanted to build a simple sub-header, exactly the same
I am using Python 3.1 by the way. I am trying to build a
I'm trying to build a quick and simple image uploading service with Node, that
I am trying to build a simple app that will show a bidimensional, scrollable

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.