Here is the complete jquery plugin that solves this problem:
https://github.com/bigspotteddog/ScrollToFixed
The description of this plugin is as follows:
This plugin is used to fix elements at the top of the page if the element scrolls out of view, vertically; however, it allows the item to continue to move left or right by scrolling horizontally.
Given the marginTop parameter, the element will stop moving vertically up as soon as the vertical scroll reaches the target position; but the item will still move horizontally as the page scrolls left or right. When the page is scrolled back to the final position, the element will be restored to its original position on the page.
This plugin has been tested in Firefox 3/4, Google Chrome 10/11, Safari 5, and Internet Explorer 8/9.
Use for your specific case:
<script src="scripts/jquery-1.4.2.min.js" type="text/javascript"></script> <script src="scripts/jquery-scrolltofixed-min.js" type="text/javascript"></script> $(document).ready(function() { $('#mydiv').scrollToFixed({ marginTop: 250 }); });
bigspotteddog Aug 29 '11 at 16:49 2011-08-29 16:49
source share