Created
November 10, 2012 16:26
-
-
Save franzenzenhofer/4051578 to your computer and use it in GitHub Desktop.
jquery plugin that replaces elements with absolute positioned clones of themselves, while hiding & silencing the originals
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
(function($){ | |
isString = function (obj) { | |
return toString.call(obj) == '[object String]'; | |
}; | |
$.fn.bodysnatch = function() { | |
var collection = this; | |
return collection.each(function(a,b) { | |
var element = $(this); | |
var clone = element.clone(); | |
w = element.width() | |
h = element.height() | |
if ( w && h) | |
{ | |
clone.attr('style', window.getComputedStyle(element[0]).cssText); | |
clone.css({ | |
position: 'absolute', | |
top: element.offset().top, | |
left: element.offset().left, | |
width: element.width(), | |
height: element.height(), | |
margin:0, | |
//padding: 0 | |
}); | |
} | |
else //probably images without a width and height yet | |
{ | |
clone.css({ | |
position: 'absolute', | |
top: element.offset().top, | |
left: element.offset().left, | |
margin:0, | |
//padding: 0 | |
}); | |
} | |
$('body').append(clone); | |
if(element[0].id) { | |
element[0].id=element[0].id+'_snatched'; | |
} | |
element.addClass('snatched'); | |
clone.addClass('bodysnatcher'); | |
//stop audio and videos | |
element.css('visibility','hidden'); | |
if(element[0].pause){ | |
element[0].pause(); | |
element[0].src=''; | |
} | |
collection[a]=clone[0] | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment