Показать сообщение отдельно
  #1 (permalink)  
Старый 08.06.2015, 10:13
Новичок на форуме
Отправить личное сообщение для kordDem Посмотреть профиль Найти все сообщения от kordDem
 
Регистрация: 08.06.2015
Сообщений: 1

Созданеи клона объекта
Добрый день новичёк в js. Потому возник вопрос)
Есть объект хочу при перетаскивание на другой участок экрана создавать новый объект, точно такой же. Вот до чего дошел:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<style>
#points{
	width: 10px; 
	height: 10px; 
	background: green; 
	-moz-border-radius: 50px;
	-webkit-border-radius: 50px; 
	border-radius: 50px;
}
</style>

</head>
<body>
<div id="points" class="points" onclick="tranzet(id)"></div> <br>
<script>
	function tranzet(id){
		var point = document.getElementById(id);
		point.onmousedown = function(e) {
			point.ondragstart = function() {
				return false;
			};
			var clon=document.createElement('div');
                        clon.className='points';
                        document.body.appendChild(clon);
                        clon.style.position = 'absolute';
                        point.style.position = 'absolute';
                        moveAt(e);
                        document.body.appendChild(point);
                        function moveAt(e) {
				clon.style.left = e.pageX - point.offsetWidth / 2 + 'px';
				clon.style.top = e.pageY - point.offsetHeight / 2 + 'px';
			}
                        document.onmousemove = function(e) {
				moveAt(e);
			}
			point.onmouseup = function() {
				document.onmousemove = null;
				ball.onmouseup = null;
			}
		}
	}
</script>
	</div>
	</body>
</html>
Ответить с цитированием