2
<div>
에는 "droppable"클래스의 세 이미지가 포함되어 있습니다. 테이블에는 마지막 행 <td>
안에 이미지가있는 4 개의 행이 있습니다.drappable 이미지로 droppable의 이미지 소스 변경
html로는 다음과 같습니다
테이블의 이미지는 위의 빈 상자로 드래그 할 수 있습니다
<div id="box_container">
<img id="empty_box1" class="droppable" src="images/tom.png" />
<img id="empty_box2" class="droppable" src="images/tom.png" />
<img id="empty_box3" class="droppable" src="images/tom.png" />
</div>
<td><img id="" class="draggable" src="images/image1.png" /></td>
다음은 레이아웃이 다음과 같은 방법의 사진입니다 탁자. 상자는 공백 이미지로 구성되어 있으며 이미지 원본을 빈 상자에 놓은 이미지로 변경합니다. 당신은 (일반적으로 ui
라는 이름으로) 두 번째 인수의 draggable
속성을 통해 삭제 된 드래그 할 수있는 요소를 액세스 할 수 있으며, drop
이벤트 콜백 내부
$(document).ready(function() {
$(".draggable").draggable({
revert: true,
snap: ".droppable",
snapMode: "inner"
});
$("#tabellen").tablesorter();
$(".droppable").droppable({
accept: ".draggable",
drop: function() {
console.log(this);
var new_pic = $('.draggable').attr('src');
$(this)
.attr('src', new_pic)
.attr('width', 150)
.attr('height', 150)
.addClass('zoomable');
}
});
});
그래서 질문은 무엇인가 : 다음과 같이 당신은 는 낙하 할에 소스의 복사 할 수 있습니다? – Evgeniy
질문은 빈 상자에 이미지를 가져 와서 이미지 위에 놓을 이미지로 변경하는 방법입니다. – Rinusu
welcome to stackOverflow. 단순한 이미지가 아닌 JS로 게임하는 데 필요한 상용구 HTML 및 CSS를 제공하면 도움이되는 사람들에게 큰 도움이됩니다. 그대로, 우리는'# draggable1','# draggable2' 등이 무엇인지, 또는 HTML 구조를 알지 못합니다. 질문을 수정하고 더 많은 정보로 업데이트하십시오. BTW에서는 초기화 옵션이 다른 경우가 아니라면'id'로 각 드래그 가능 객체를 하나씩 초기화하는 대신 공통 클래스를 사용해야합니다. –