$( window ).scrollTop( 1 );
return $( window ).scrollTop() === 1;
}
-function getScrollbarWidth() {
- var div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
- innerDiv = div.children()[0],
- w1, w2;
- $( "body" ).append( div );
- w1 = innerDiv.offsetWidth;
- div.css( "overflow", "scroll" );
-
- w2 = innerDiv.offsetWidth;
-
- if ( w1 === w2 ) {
- w2 = div[0].clientWidth;
- }
-
- div.remove();
-
- return w1 - w2;
-}
-function getScrollInfo ( within ) {
- var that = within[0],
- scrollHeight = within.height() < that.scrollHeight,
- scrollWidth = within.width() < that.scrollWidth,
- scrollbarWidth = getScrollbarWidth();
- return { height : scrollHeight ? scrollbarWidth : 0, width : scrollWidth ? scrollbarWidth : 0 };
-};
module( "position - within", {
setup: function(){
collisionTest({
collision: "fit"
- }, { top: addTop + within.height() - 10 - getScrollInfo( within ).height, left: addLeft + within.width() - 10 - getScrollInfo( within ).width }, "right bottom" );
+ }, { top: addTop + within.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom" );
collisionTest2({
collision: "fit"
collisionTest({
collision: "fit",
at: "right+2 bottom+3"
- }, { top: addTop + within.height() - 10 - getScrollInfo( within ).height, left: addLeft + within.width() - 10 - getScrollInfo( within ).width }, "right bottom");
+ }, { top: addTop + within.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom");
collisionTest2({
collision: "fit",
collisionTest2({
collision: "fit",
at: "right+100 bottom+100"
- }, { top: addTop + within.height() - 10 - getScrollInfo( within ).height, left: addLeft + within.width() - 10 - getScrollInfo( within ).width }, "right bottom" );
+ }, { top: addTop + within.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom" );
within.scrollTop( 0 ).scrollLeft( 0 );
}
});
collisionTest({
collision: "fit"
- }, { top: addTop + within.height() - 20 - getScrollInfo( within ).height, left: addLeft + within.width() - 20 - getScrollInfo( within ).width }, "right bottom" );
+ }, { top: addTop + within.height() - 20 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 20 - $.position.getScrollInfo( within ).width }, "right bottom" );
collisionTest2({
collision: "fit"
collisionTest({
collision: "fit"
- }, { top: addTop + within.height() - 20 - getScrollInfo( within ).height, left: addLeft + within.width() - 20 - getScrollInfo( within ).width }, "right bottom" );
+ }, { top: addTop + within.height() - 20 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 20 - $.position.getScrollInfo( within ).width }, "right bottom" );
collisionTest2({
collision: "fit"
collisionTest({
collision: "fit"
- }, { top: addTop + within.height() - 25 - getScrollInfo( within ).height, left: addLeft + within.width() - 25 - getScrollInfo( within ).width }, "right bottom" );
+ }, { top: addTop + within.height() - 25 - $.position.getScrollInfo( within ).height, left: addLeft + within.width() - 25 - $.position.getScrollInfo( within ).width }, "right bottom" );
collisionTest2({
collision: "fit"
rposition = /^\w+/,
rpercent = /%$/,
center = "center",
- _position = $.fn.position,
- getScrollbarWidth = function() {
+ _position = $.fn.position;
+
+$.position = {
+ scrollbarWidth : function() {
var div = $( "<div style='display:block;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
innerDiv = div.children()[0],
w1, w2;
return w1 - w2;
},
- getScrollInfo = function( within ) {
+ getScrollInfo : function( within ) {
var that = within[0],
scrollHeight = within.height() < that.scrollHeight,
scrollWidth = within.width() < that.scrollWidth,
- scrollbarWidth = getScrollbarWidth();
+ scrollbarWidth = $.position.scrollbarWidth();
return { height : scrollHeight ? scrollbarWidth : 0, width : scrollWidth ? scrollbarWidth : 0 };
- };
+ }
+};
$.fn.position = function( options ) {
if ( !options || !options.of ) {
elemHeight = elem.outerHeight(),
marginLeft = parseInt( $.curCSS( this, "marginLeft", true ) ) || 0,
marginTop = parseInt( $.curCSS( this, "marginTop", true ) ) || 0,
- scrollInfo = getScrollInfo( within ),
+ scrollInfo = $.position.getScrollInfo( within ),
collisionWidth = elemWidth + marginLeft +
( parseInt( $.curCSS( this, "marginRight", true ) ) || 0 ) + scrollInfo.width,
collisionHeight = elemHeight + marginTop +