Permalink
Browse files

fixes position top not working at all and a float for position bug

  • Loading branch information...
Glench committed Oct 29, 2011
1 parent 871f73c commit a9b2e308c0d9a16bf19aa0d12cce6b706b412dcd
Showing with 7 additions and 6 deletions.
  1. +6 −4 jquery.floatScroll.js
  2. +1 −2 sample.html
View
@@ -44,13 +44,14 @@ $.fn.floatScroll = function(map){
left: $this.css('left'),
width: $this.css('width'),
zIndex: $this.css('z-index'),
- marginTop: $this.css('margin-top')
+ marginTop: $this.css('margin-top'),
+ 'float': $this.css('float')
}
var old_offset = $this.offset();
// On scroll, figure out what this element's positioning should be.
$window.scroll(function() {
- if (old_offset.top > $window.scrollTop()) {
+ if (old_offset.top - opts.positionTop > $window.scrollTop()) {
// Remove old placeholder(s) and put this thing back into
// position.
if ($this.data(opts.placeholderClass)) {
@@ -66,7 +67,8 @@ $.fn.floatScroll = function(map){
var $placeholder = $('<div>', {
'class': opts.placeholderClass,
width: $this.outerWidth(true),
- height: $this.outerHeight(true)
+ height: $this.outerHeight(true),
+ 'css': {'float':old_css.float}
});
$this.after($placeholder);
$this.data(opts.placeholderClass, $placeholder);
@@ -80,7 +82,7 @@ $.fn.floatScroll = function(map){
top: opts.positionTop,
left: smart_left_offset($this, old_offset),
width: $this.css('width'),
- marginTop: opts.positionTop,
+ marginTop: 0,
zIndex: opts.zIndex
});
}
View
@@ -35,7 +35,6 @@
}
#sidebar {
float:right;
- margin-top: 30px;
width:230px;
padding:10px;
background:#99c;
@@ -82,7 +81,7 @@ <h2>floatScroll!!!</h2>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="jquery.floatScroll.js"></script>
<script type="text/javascript">
- $('#sidebar').floatScroll();
+ $('#sidebar').floatScroll({positionTop: 30});
</script>
</body>
</html>

0 comments on commit a9b2e30

Please sign in to comment.