jQuery drag and drop expands -
what want drag cube on box. box expands , cube can placed on 1 of 3 'timelines'.
my html:
<div class="drag"></div> <div class="addroom one"> <div class="timeline"> <div id="t1"></div> <div id="t2"></div> <div id="t3"></div> </div> </div> <div class="addroom two"> <div class="timeline"> <div id="t1"></div> <div id="t2"></div> <div id="t3"></div> </div> </div> my javascript:
$(function () { $(".drag").draggable({ revert: "invalid", snap: '#t3, #t2, #t1', snapmode: 'inner' }); $(".timeline").droppable({ over: function (event, ui) { $(this).css('height', "66px"); $(".timeline #t1").droppable({}); $(".timeline #t2").droppable({}); $(".timeline #t3").droppable({}); }, out: function (event, ui) { $(this).css('height', "24px"); }, drop: function (event, ui) { $(this).css('height', "24px"); } }); }); jsfiddle: http://jsfiddle.net/h7xv9/
as can see possible drop on t1, t2 , t3.but want t2 , t3 droppable when timeline expanded!
use:
overflow:hidden on t2 , t3
also, converted them class rather id. it's illegal have multiple ids in real world, should illegal in html too.
update ops comments
markup
to each t# class added drop class
<div class="drag"></div> <div class="addroom one"> <div class="timeline"> <div class="drop t1"></div> <div class="drop t2"></div> <div class="drop t3"></div> </div> </div> <div class="addroom two"> <div class="timeline"> <div class="drop t1"></div> <div class="drop t2"></div> <div class="drop t3"></div> </div> </div> javascript
$(function () { $(".drag").draggable({ revert: "invalid", snap: '.t3, .t2, .t1', snapmode: 'inner' }); $(".drop").droppable({ // assign event drop class over: function (event, ui) { $(this).parent().css('height', "66px"); }, out: function (event, ui) { $(this).parent().css('height', "24px"); }, drop: function (event, ui) { $(this).parent().css('height', "24px"); } }); });
Comments
Post a Comment