简体   繁体   中英

Copy/Paste function using JQuery .clone()

I am trying to implement a copy/paste function for a pipeline game. I am using JS & JQuery and for this feature I use.clone().

  1. Is it necessary to "play" with the ID? May I just play with variable?
  2. Is there any easy feature to paste on the mouse hover instead of coordinate?
$(document).keydown(function(e) {
  if (ctrlDown && (e.keyCode == cKey)) $('block-selected').clone().RemoveAttr("id").appendTo('clipboard');
  if (ctrlDown && (e.keyCode == vKey)) paste($('clipboard').parent().clone(), { top: 160, left: 840 }, true, 0);
})

Going to wing this a bit due to a lack of exact purpose...

Judging by your code you want to be able to copy elements into a clipboard and then be able to paste them to a specified position on the page, preferably at current mouse position?

"Playing" with the ID is not "needed" per se, but you want to avoid having multiple elements with the same ID, Maybe use some sort of Counter so you have ID1, ID2 etc, that way they'd be unique.

I don't think there is a builtin feature to paste at the current Mouse Position. However you could add an eventlistener to the window's 'mousemove' and store the X,Y in a variable and then paste at that position.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM