How to adjust the size of multiple adjacent textareas like in jsfiddle.net?

廉价感情. 提交于 2019-12-04 08:15:54
Koray S.

Can you please check this solution: http://jsfiddle.net/xBjnY/9/

$(function() {
    window.onresize = resize;
    resize();
});

function resize() {
    var h = (window.innerHeight || (window.document.documentElement.clientHeight || window.document.body.clientHeight));
    var divHight = 20 + $("#div_left").height(); //20=body padding:10px
    $("#content").css({
        "min-height": h - divHight + "px"
    });
    $("#div_vertical").css({
        "height": h - divHight + "px"
    });
    $("#LeftPanel").css({
        "height": h - divHight + "px"
    });
    $("#RightPanel").css({
        "height": h - divHight + "px",
        "width": $("#content").width() - $("#LeftPanel").width() - $("#div_vertical").width() + "px"
    });
}

jQuery.resizable = function(resizerID, vOrH) {
    jQuery('#' + resizerID).bind("mousedown", function(e) {
        var start = e.pageY;
        if (vOrH == 'v') start = e.pageX;
        jQuery('body').bind("mouseup", function() {
            jQuery('body').unbind("mousemove");
            jQuery('body').unbind("mouseup");

        });
        jQuery('body').bind("mousemove", function(e) {
            var end = e.pageY;
            if (vOrH == 'v') end = e.pageX;
            if (vOrH == 'h') {
                jQuery('#' + resizerID).prev().height(jQuery('#' + resizerID).prev().height() + (end - start));
                jQuery('#' + resizerID).next().height(jQuery('#' + resizerID).next().height() - (end - start));
            }
            else {
                jQuery('#' + resizerID).prev().width(jQuery('#' + resizerID).prev().width() + (end - start));
                jQuery('#' + resizerID).next().width(jQuery('#' + resizerID).next().width() - (end - start));
            }
            start = end;
        });
    });
}

jQuery.resizable('div_vertical', "v");
jQuery.resizable('div_right', "h");
jQuery.resizable('div_left', "h");

Is it what you are looking for? Does it help?

You need to write some hardcore JavaScript code. ;) On mousedown event you store mouse position and in setTimeout (or setInterval) you check current mouse position (for example like once evey 16 miliseconds to get ~60FPS so it looks good). Then you evaluate the difference between starting mouse position and current mouse position and update the css/width/height.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!