View Single Post
Old 12-15-2012, 05:08 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
mouseover is not a good choice because, as you have discovered, you can end up with lots of clones. mousedown is probably more sensible, but you need to check that you only have one clone at any time:

Code:
var theImage = document.getElementById("imageID"); // jQuery: $('#imageID')
var theClone = theClone || theImage.cloneNode(true); // jQuery: theImage.clone()
Then use mouseup to either insert the clone (or not) and set theClone = null (jQuery: .remove() ..? if you must . No, I think this removes an existing element from the DOM: just set it to null.)

BTW
Code:
var theClone = theClone || theImage.cloneNode(true);
is my favourite JS statement; we cannot do this in most any other language - or, at least, not as simply as this.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 12-15-2012 at 05:33 PM..
AndrewGSW is offline   Reply With Quote