Browse Source

#2710 merge and modify this context

pull/2755/merge
Jack Lukic 9 years ago
parent
commit
09ecab67fc
1 changed files with 35 additions and 28 deletions
  1. 63
      src/definitions/modules/sticky.js

63
src/definitions/modules/sticky.js

@ -129,6 +129,7 @@ $.fn.sticky = function(parameters) {
determineContainer: function() { determineContainer: function() {
$container = $module.offsetParent(); $container = $module.offsetParent();
console.log($container);
}, },
determineContext: function() { determineContext: function() {
@ -390,8 +391,8 @@ $.fn.sticky = function(parameters) {
}, },
size: function() { size: function() {
if(module.cache.element.height !== 0 && module.cache.element.width !== 0) { if(module.cache.element.height !== 0 && module.cache.element.width !== 0) {
$module.get(0).style.setProperty('width', module.cache.element.width + 'px', 'important');
$module.get(0).style.setProperty('height', module.cache.element.height + 'px', 'important');
element.style.setProperty('width', module.cache.element.width + 'px', 'important');
element.style.setProperty('height', module.cache.element.height + 'px', 'important');
} }
} }
}, },
@ -445,16 +446,17 @@ $.fn.sticky = function(parameters) {
if(elementVisible) { if(elementVisible) {
if( module.is.initialPosition() ) { if( module.is.initialPosition() ) {
if(scroll.top > context.bottom) {
module.debug('Element bottom of container');
if(scroll.top >= context.bottom) {
module.debug('Initial element position is bottom of container');
module.bindBottom(); module.bindBottom();
} }
else if(scroll.top > element.top) { else if(scroll.top > element.top) {
module.debug('Element passed, fixing element to page');
if( (element.height + scroll.top - elementScroll) > context.bottom ) {
if( (element.height + scroll.top - elementScroll) >= context.bottom ) {
module.debug('Initial element position is bottom of container');
module.bindBottom(); module.bindBottom();
} }
else { else {
module.debug('Initial element position is fixed');
module.fixTop(); module.fixTop();
} }
} }
@ -464,11 +466,11 @@ $.fn.sticky = function(parameters) {
// currently fixed top // currently fixed top
if( module.is.top() ) { if( module.is.top() ) {
if( scroll.top < element.top ) {
if( scroll.top <= element.top ) {
module.debug('Fixed element reached top of container'); module.debug('Fixed element reached top of container');
module.setInitialPosition(); module.setInitialPosition();
} }
else if( (element.height + scroll.top - elementScroll) > context.bottom ) {
else if( (element.height + scroll.top - elementScroll) >= context.bottom ) {
module.debug('Fixed element reached bottom of container'); module.debug('Fixed element reached bottom of container');
module.bindBottom(); module.bindBottom();
} }
@ -484,12 +486,12 @@ $.fn.sticky = function(parameters) {
else if(module.is.bottom() ) { else if(module.is.bottom() ) {
// top edge // top edge
if( (scroll.bottom - element.height) < element.top) {
if( (scroll.bottom - element.height) <= element.top) {
module.debug('Bottom fixed rail has reached top of container'); module.debug('Bottom fixed rail has reached top of container');
module.setInitialPosition(); module.setInitialPosition();
} }
// bottom edge // bottom edge
else if(scroll.bottom > context.bottom) {
else if(scroll.bottom >= context.bottom) {
module.debug('Bottom fixed rail has reached bottom of container'); module.debug('Bottom fixed rail has reached bottom of container');
module.bindBottom(); module.bindBottom();
} }
@ -504,13 +506,13 @@ $.fn.sticky = function(parameters) {
} }
else if( module.is.bottom() ) { else if( module.is.bottom() ) {
if(settings.pushing) { if(settings.pushing) {
if(module.is.bound() && scroll.bottom < context.bottom ) {
if(module.is.bound() && scroll.bottom <= context.bottom ) {
module.debug('Fixing bottom attached element to bottom of browser.'); module.debug('Fixing bottom attached element to bottom of browser.');
module.fixBottom(); module.fixBottom();
} }
} }
else { else {
if(module.is.bound() && (scroll.top < context.bottom - element.height) ) {
if(module.is.bound() && (scroll.top <= context.bottom - element.height) ) {
module.debug('Fixing bottom attached element to top of browser.'); module.debug('Fixing bottom attached element to top of browser.');
module.fixTop(); module.fixTop();
} }
@ -554,6 +556,7 @@ $.fn.sticky = function(parameters) {
}, },
setInitialPosition: function() { setInitialPosition: function() {
module.debug('Returning to initial position');
module.unfix(); module.unfix();
module.unbind(); module.unbind();
}, },
@ -596,24 +599,28 @@ $.fn.sticky = function(parameters) {
}, },
unbind: function() { unbind: function() {
module.debug('Removing absolute position on element');
module.remove.offset();
$module
.removeClass(className.bound)
.removeClass(className.top)
.removeClass(className.bottom)
;
if( module.is.bound() ) {
module.debug('Removing container bound position on element');
module.remove.offset();
$module
.removeClass(className.bound)
.removeClass(className.top)
.removeClass(className.bottom)
;
}
}, },
unfix: function() { unfix: function() {
module.debug('Removing fixed position on element');
module.remove.offset();
$module
.removeClass(className.fixed)
.removeClass(className.top)
.removeClass(className.bottom)
;
settings.onUnstick.call(element);
if( module.is.fixed() ) {
module.debug('Removing fixed position on element');
module.remove.offset();
$module
.removeClass(className.fixed)
.removeClass(className.top)
.removeClass(className.bottom)
;
settings.onUnstick.call(element);
}
}, },
reset: function() { reset: function() {
@ -819,7 +826,7 @@ $.fn.sticky.settings = {
name : 'Sticky', name : 'Sticky',
namespace : 'sticky', namespace : 'sticky',
debug : false,
debug : true,
verbose : true, verbose : true,
performance : true, performance : true,

Loading…
Cancel
Save