Move/Fix a DIV element to top upon scrolling the page

Please find below a sample HTML code that fixes the position of a DIV element. Now, I need to be able to move the "setupBar" to (0,0) position (or appropriate position based on where the scroll position is) once I start scrolling and then just freeze it.

Please advise.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div id="mainBar" style="height:20px; border:1px solid red"></div>
<div id="setupBar" style="position:fixed; border:1px solid blue; height:20px; width:100%"></div>
<div style="height:1500px; background-color:#CCCCCC"></div>
</body>
</html>

Open in new window

LVL 32
ldbkuttyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cenjoy100Commented:
0
Kiran SonawaneProject LeadCommented:
Try this

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body>
<div id="mainBar" style="height:20px; border:1px solid red"></div>
<div id="setupBar" style="position:fixed; border:1px solid blue; height:20px; width:100%;margin:-20px 0px 0px 0px;"></div>
<div style="height:1500px; background-color:#CCCCCC"></div>
</body>
</html>

Open in new window

0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

ldbkuttyAuthor Commented:
The first link is a CSS fix which isn't what I am looking for, and the second link seems to also irrelevant :(
0
ldbkuttyAuthor Commented:
sonawanekiran, i'd like to adjust (and freeze) the "setupBar" according to the current scroll position is ...
0
Kiran SonawaneProject LeadCommented:
Here is fix using jquery

<!DOCTYPE HTML>
  <head>
    <title>Delayed Observer</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $("#setupBar").offset({left:e.pageX,top:e.pageY});
      });
    </script>
  </head>
  <body>
  <div id="mainBar" style="height:20px; border:1px solid red"></div>
<div id="setupBar" style="position:fixed; border:1px solid blue; height:20px; width:100%;margin:-20px 0px 0px 0px;"></div>
<div style="height:1500px; background-color:#CCCCCC"></div>
  </body>
</html>
0
ldbkuttyAuthor Commented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ldbkuttyAuthor Commented:
This solution is simple, and uses plain JS ...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.