나는 사업부 콘텐츠라는이만들 크기 조정이 가능한 동적으로 추가 사업부
<div id="content">
</div>
I가 다른 사업부 호출 악기
<div id="instruments">
</div>
나는 그것이 사업부라는 내용에 추가 할 수있는 계기를 클릭하면 . 나는이 일을했다. 하지만 이동 된 div (악기)는 크기를 조정할 수 있어야합니다. 나는 jquery-ui.js를 사용해 보았지만 실패했다. 나는 무엇을 할 것인가? 당신은 당신이 대신 .on()
의 .one()
을 가지고 있고 당신이 당신의 HTML에 id="instruments"
를 사용하여 자바 스크립트 구문 오류가
<script>
var steps_array = [];
$(".instruments").one("click", function(){
$("#content").append($(this));
$(this).css({"position":"relative", "top":"10px"});
$(this).addClass('resizable');
steps_array.push({
id : $(this).attr('id'),
height: $(this).height(),
width: $(this).width(),
positionX: $(this).position().left,
positionY: $(this).position().top
});
$(this).draggable({
containment: "parent",
drag: function() {
$("#x-value").html($(this).position().top);
changePos ($(this).attr('id'), $(this).position().left , $(this).position().top);
console.log("Edited : "+$(this).attr('id'));
}
});
$(".resizable").resizable();
});
$(".btn").click(function(){
print_array_object(steps_array);
});
function print_array_object(array_name){
$.each(array_name, function(index, val) {
console.log(val.id);
console.log(val.height);
console.log(val.width);
console.log(val.positionX);
console.log(val.positionY);
});
}
function changePos(id, newX , newY) {
for (var i in steps_array) {
if (steps_array[i].id == id) {
steps_array[i].positionX = newX;
steps_array[i].positionY = newY;
break; //Stop this loop, we found it!
}
}
}
</script>
당신은 바이올린, 그런 식으로 :) –
변경 $ (". 악기")를 파악하기 쉬운 것입니다 수 있습니다. 하나 (($로, 기능() 를 "클릭" "#instruments"). 악기가 ID이기 때문에 one ("click", function() ). 가능하면 피들을 만드십시오. – Tanul
jQuery에서 아무도 이벤트가 아닙니다. 두 번째로 이벤트가 발생하면 첫 번째 이벤트가 꺼질 것입니다. 참조 용 http://api.jquery.com/one/ – nifCody