Skip to content

Commit

Permalink
Don't create a new backstretch div if one already exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
srobbin committed Jun 19, 2013
1 parent 6d6cc2f commit 6e4bae9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/jquery.backstretch.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,12 @@
* Root: Convenience reference to help calculate the correct height.
*/
this.$container = $(container);
this.$wrap = $('<div class="backstretch"></div>').css(styles.wrap).appendTo(this.$container);
this.$root = this.isBody ? supportsFixedPosition ? $(window) : $(document) : this.$container;

// Don't create a new wrap if one already exists (from a previous instance of Backstretch)
var $existing = this.$container.children(".backstretch").first();
this.$wrap = $existing.length ? $existing : $('<div class="backstretch"></div>').css(styles.wrap).appendTo(this.$container);

// Non-body elements need some style adjustments
if (!this.isBody) {
// If the container is statically positioned, we need to make it relative,
Expand Down

0 comments on commit 6e4bae9

Please sign in to comment.