Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added ability to regard element position as "fixed" - this is not sup…

…ported in IE 6 however
  • Loading branch information...
commit 289066c91051ede910af9d77e68bbe3b4fcb5016 1 parent 31b202d
@traversal authored
Showing with 28 additions and 6 deletions.
  1. +4 −3 src/jquery.traversal.affix.js
  2. +24 −3 test/index.html
View
7 src/jquery.traversal.affix.js
@@ -149,7 +149,8 @@ offsets
glue : { to: "ne" }, // default case is for the most common form of "tooltip"
glueInsideWindow : true,
offsets : [0,0],
-
+ fixed : false,
+
// inset [x,y] can be used instead of (or in addition to offsets), which intelligently apply offsets with respect to the glue position.
// positive inset will position INSIDE the boundary of that which we are hooking "to", negative inset will position OUTSIDE
// a single integer value can also be used to apply equal [x,y] inset
@@ -612,11 +613,11 @@ offsets
}
case "wx":
{
- return wo.left;
+ return settings.fixed ? 0 : wo.left;
}
case "wy":
{
- return wo.top;
+ return settings.fixed ? 0 : wo.top;
}
case "fw": {
return fs.width;
View
27 test/index.html
@@ -21,6 +21,8 @@
(function($){
+ var updateTimeout;
+
function iupdate()
{
update(true);
@@ -28,6 +30,15 @@
function update(instant)
{
+ if ($('#fixed_mode')[0].checked)
+ {
+ $('#from_element').css({position: "fixed"});
+ }
+ else
+ {
+ $('#from_element').css({position: "absolute"});
+ }
+
var offsets = {
"*" : [$('#offset_x').val(), $('#offset_y').val()]
};
@@ -65,7 +76,8 @@
to: to,
animate: instant !== true,
offsets: offsets,
- inset: inset
+ inset: inset,
+ fixed: $('#fixed_mode')[0].checked
}
);
}
@@ -79,7 +91,8 @@
glueInsideWindow: $('#glue_inside_window')[0].checked,
animate: instant !== true,
offsets: offsets,
- inset: inset
+ inset: inset,
+ fixed: $('#fixed_mode')[0].checked
}
);
}
@@ -103,8 +116,10 @@
$('#offset_y_val').change(update);
$('#glue_inside_window').change(update);
+ $('#fixed_mode').click(update);
+
$(window).resize(iupdate);
- $(window).scroll(iupdate);
+ $(window).scroll( function() { if (!($('#fixed_mode')[0].checked)) iupdate() } );
$("#ten" ).click(function() { $('#fix_to').val("element"); $('#glue_to').val("n"); update(); });
$("#tene").click(function() { $('#fix_to').val("element"); $('#glue_to').val("ne"); update(); });
@@ -187,6 +202,12 @@ <h1 class="ir">Traversal - JavaScript Plugins</h1>
<option>window</option>
<option>offscreen</option>
</select>
+
+ <span id="wrap_fixed_mode">
+ &nbsp;&nbsp;&nbsp;&nbsp;
+ <input id="fixed_mode" type="checkbox" value="1" class="checkbox" />
+ <label for="fixed_mode">Use Fixed Position (will set to element to "position: fixed", and suppress scroll events)</label>
+ </span>
<div class="padder"></div>
Please sign in to comment.
Something went wrong with that request. Please try again.