How can I resize a DIV by dragging just ONE side of it?

前端 未结 9 2268
后悔当初
后悔当初 2020-12-12 17:38

Let me be more specific... I don\'t want the DIV to resize WHILE I\'m dragging. I want to drag it out (and maybe a vertical line follows my cursor) and when I release, it re

9条回答
  •  孤城傲影
    2020-12-12 18:09

    Have a look at this example

    Html

    
    
    main

    jquery

    var dragging = false;
    $('#dragbar').mousedown(function(e){
       e.preventDefault();
    
       dragging = true;
       var main = $('#main');
       var ghostbar = $('
    ', {id:'ghostbar', css: { height: main.outerHeight(), top: main.offset().top, left: main.offset().left } }).appendTo('body'); $(document).mousemove(function(e){ ghostbar.css("left",e.pageX+2); }); }); $(document).mouseup(function(e){ if (dragging) { $('#sidebar').css("width",e.pageX+2); $('#main').css("left",e.pageX+2); $('#ghostbar').remove(); $(document).unbind('mousemove'); dragging = false; } });

    Demo at http://jsfiddle.net/gaby/Bek9L/1779/

    it is an alteration from the code i posted in Emulating frame-resize behavior with divs using jQuery without using jQuery UI?

提交回复
热议问题