Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to resize a div with mouse drag with html css and javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 11.4k
    Comment on it

    Have you ever taken a risk at doing some movement utilizing plain Javascript or moving DIVs here and there or resizing them?! All things considered, you know then the amount of torment it is as not just you need to handle the troublesome piece of liveliness additionally making it cross program good.

    Well you most likely know why I am extending up so hard is just to let you know that it is so natural to utilize jQuery and do some truly incredible things without irritating of knowing how it is done inside. jQuery accompanies truly valuable UI library that can be consolidated to do such traps.

    In this little note, I will demonstrate to you generally accepted methods to do Resizing  a DIV utilizing jQuery. I will demonstrate to you the demo of a DIV, which can be resized by pulling up the dragbar .There are two div and between the two div there is a dragbar with the help of the dragbar you can pull the div according to your need.


    Step 1: Including the jQuery

    <script src="" type="text/javascript"></script>


    Step 2: Write Html to Resize the Div with mouse drag

    <!DOCTYPE html>
    		resize div
        /*This is the main div under which main div and sidebar div reside*/
    	<div class="wrap">
    	<div id="sidebar"> /*this is the first div*/
    	     <span id="position"></span> /*setting the position of the div*/
    	     This is the sidebar div
    	<div id="dragbar"></div> /*this is the div with the help of which we can resize the div accordingly*/
    	<div id="main"> /*this is the second div*/
    	   This is the main div
    	<div id="console"></div>


    Step 3: Writing the Css to set the div accordingly

    .clearfix:after {
        content: '';
        display: table;
        clear: both;
    /* first div*/
       background-color: #BD6982;
        height: 75%;
    /*second div*/
       background-color: #85BD40;
       overflow-y: hidden;
    /* div which is used to drag for resizing */
      width :100%;
       height : 3px;
       cursor: col-resize;
    /* bar which show how much you want to resize  */
        cursor: col-resize;
      .wrap{height: 600px;}


    Step 4: Writing jQuery Code

    var i = 0;
    var dragging = false;
           dragging = true;
           var main = $('#main');
           var ghostbar = $('<div>',
                             css: {
                                    width: main.outerWidth(),
                                    top: main.offset().top,
                                    left: main.offset().left
           if (dragging) 
               var percentage = (e.pageY / window.innerHeight) * 100;
               var mainPercentage = 100-percentage;
               $('#console').text("side:" + percentage + " main:" + mainPercentage);
               $('#sidebar').css("height",percentage + "%");
               $('#main').css("height",mainPercentage + "%");
               dragging = false;

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: