当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - jquery draggable - resize selector while dragging

问题描述:

I have a problem with Jquery draggable, I want to drag a DIV and while dragged I will resize the DIV. Seems like Jquery calculate the height/width of the Selector just at initiation, after resize it will calculate the height/width from the begining not the actual/live and if I use a container it will not work properly.

Here is an example : http://jsfiddle.net/zwQ2S/

$("#selector").draggable({ containment: "#container", scroll: false});

$("#selector").draggable( "option", "axis", "y");

$("#container").mousemove(function() {

var margin =parseInt($("#selector").css("top"));

if (margin > 10){

$("#selector").css("height", "100px");

}

});

PS: I want to use draggable for a scrollbar with dynamic content/loading.

网友答案:

I found a solution Here, the final fiddle : http://jsfiddle.net/XLrNF/178/

     var $container = $("#demo");
function resizeContainer(e, ui) {
    //resize container here
    var w1 = ui.helper.outerHeight(),
        w2 = $container.height();
    //console.log([ui.position.left, w1, w2].join(' : '));
    ui.position.top = Math.max(Math.min(ui.position.top, w2 - w1), 0);
}
$("#draggable").draggable({
    axis: "y",
    drag: resizeContainer
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: