Created
May 21, 2014 13:44
-
-
Save philbirnie/d3b9594f94f96635dd77 to your computer and use it in GitHub Desktop.
Dead simple position mover for an element or two to keep everything tidy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint browser: true*/ | |
/*global jQuery */ | |
var QuickBrick = { | |
topEntity: null, | |
bottomEntity: null, | |
init: function (top, bottom) { | |
"use strict"; | |
this.topEntity = top; | |
this.bottomEntity = bottom; | |
}, | |
recalculate: function () { | |
"use strict"; | |
var topBottomPos, | |
bottomTopPos, | |
newPosition; | |
jQuery(this.bottomEntity).css( | |
{ | |
position: "static" | |
} | |
); | |
bottomTopPos = jQuery(this.bottomEntity).offset().top; | |
topBottomPos = jQuery(this.topEntity).offset().top + jQuery(this.topEntity).outerHeight(); | |
newPosition = topBottomPos - bottomTopPos; | |
jQuery(this.bottomEntity).css( | |
{ | |
top: newPosition + "px", | |
position: "relative" | |
} | |
); | |
}, | |
bindHandlers: function () { | |
"use strict"; | |
var self = this; | |
jQuery(window).on("resize", function () { | |
self.recalculate(); | |
}); | |
}, | |
destroy: function () { | |
"use strict"; | |
jQuery(window).off("resize"); | |
jQuery(this.bottomEntity).attr("style", ""); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment