Created
March 28, 2013 21:04
-
-
Save andrewkdouglas/5266778 to your computer and use it in GitHub Desktop.
Clone a section of DOM with canvas elements using jQuery
This file contains 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
// Clone DOM | |
var originalContent = $('#content'); | |
var newLocation = $('#new-location'); | |
var newContent = originalContent.clone(); | |
newContent.appendTo(newLocation); | |
// Clone the canvas across | |
var originalCanvas = originalContent.find('canvas'); | |
var cloneCanvas = newContent.find("canvas"); | |
$.each(originalCanvas, function(index, value) { | |
var originalContext = originalCanvas[index].getContext("2d"); | |
var imageData = originalContext.getImageData(0, 0, 200, 200); | |
var cloneContext = cloneCanvas[index].getContext("2d"); | |
cloneContext.putImageData(imageData, 0, 0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment