Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Ability to remove backgroundSize #8

Closed
wants to merge 3 commits into from

2 participants

@jmparsons

Added ability to remove backgroundSize from element.

@louisremi
Owner

Hi, thanks for taking the time to make this pull request.
It looks good but I'm wondering: what is the practical use case for changing the background-size (in your case, removing it)

@jmparsons

I came across needing to remove elements in a backbone application. We built a multi pane vertical layout and anything outside of the current pane is removed from the dom and re-added through ajax. The resize event is fired to adjust the layout, but it throws errors if the watched element isn't found. It was tested on ie8 and up and the latest browsers.

@jmparsons jmparsons closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 2 deletions.
  1. +14 −2 jquery.backgroundSize.js
View
16 jquery.backgroundSize.js
@@ -40,15 +40,27 @@ if ( "backgroundSize" in div.style && !$.debugBGS ) { return; }
$.cssHooks.backgroundSize = {
set: function( elem, value ) {
+
var firstTime = !$.data( elem, "bgsImg" ),
pos,
$wrapper, $img;
- $.data( elem, "bgsValue", value );
+ if (value == "") {
+ $.removeData( elem, "bgsValue");
+ $.removeData( elem, "bgsImg");
+ $.removeData( elem, "bgsPos");
+ $.removeData( elem, "bgsDim");
+ $.removeData( elem, "bgsImgDim");
+ $.removeData( elem, "bgsConstrain");
+ watched.splice( $.inArray(elem, watched), 1 );
+ return;
+ } else {
+ $.data( elem, "bgsValue", value );
+ }
if ( firstTime ) {
// add this element to the 'watched' list so that it's updated on resize
- watched.push( elem );
+ watched.push( elem );
$.refreshBackgroundDimensions( elem, true );
Something went wrong with that request. Please try again.