Instructions on creating a vertical height adjustment handle for a website

Is there a way to create a 100% height div that can be divided by a draggable border vertically? Take a look at my fiddle to see what I have so far: http://jsfiddle.net/k5rtbzs5/

This is the HTML code:

<div class="column">
  <div class="top">
      test
  </div>

    <div class="slider"></div>

  <div class="bot">
      test
  </div>
</div>

Here is the corresponding CSS:

html {
    height: 100%;
    width: 100%;
}

body {
    height: 100%;
}

.column {
    width: 100%;
    height: 100%;
    border: solid #000;
}

.top {
    width: 100%;
    height: 50%;
    background-color: #989898;
}

.bot {
    width: 100%;
    height: 50%;
    background-color: #686868;
}

.slider {
    width: 100%;
    height: 10px;
    background-color: #000;
}

Any suggestions on how I can enable the "slider" div to adjust the heights of the "top" and "bot" divs by dragging it? I also want to ensure that the "column" div maintains the full height of the browser window.

Thank you

Answer №1

To modify the height of the top and bottom divs using jQuery, you can utilize the mousemove event. Below is the jQuery code snippet that accomplishes this:

$(document).ready(function(){
  $('.slider').on('mousedown',function(e){
    $('.column').on('mousemove',function(e){
        diff = $('.slider').offset().top + 5 - e.pageY ;
        $('.top').height($('.top').height()-diff);
        $('.bot').height($('.bot').height()+diff);
    });
  });
  $('.column').on('mouseup',function(){
      $('.column').off('mousemove');
  });
});

Explore the code on jsfiddle here: http://jsfiddle.net/ndud4ff7/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sliding Toggle: Panel Revealed with Button Slide

Currently, I am working on implementing a jquery slide tab feature. The functionality is working fine on button click. However, I want the button to stick with the panel and slide along with it. At the moment, the button remains fixed while the panel slide ...

I'm curious if there is an eslint rule specifically designed to identify and flag any unnecessary spaces between a block comment and the function or

Can anyone help me find a solution to prevent the following issue: /** * This is a comment */ function foo() { ... } I need it to be corrected and formatted like this: /** * This is a comment */ function foo() { ... } ...

Choose a Vue filter according to the variable selected

My Current Table Dilemma Creating a table from a 2D array in Vue2 has been successful for me, as I've managed to display all the values correctly. However, I am facing issues with formatting. The template code is structured like this: <table> ...

How should attributes be passed to the li element properly?

I am trying to transfer values from the database to the <li> tag. Can someone confirm if the approach below is valid and the proper way to do it? <li id='$current_row["RA_SUB_ID"]' component_name='$current_row["RA_SUB_NAME"]' ...

Creating Stunning CSS Animations for a Slider Using SVG

Looking for help to create an SVG CSS animation for a slider using a mockup image. The animation will feature a balloon with a number value that zooms in and out from left to right or right to left. Currently stuck at the starting point and unsure how to ...

Error encountered: Function _ctx.showEditModal is not defined in Vue 3 + Laravel Project

Currently, I am working on a Laravel + Vue Js 3 project. Within my Tags.vue file, there is an edit button that should lead to the tag edit page. You can view the Tags.vue file through the following link: https://codepen.io/amumodaya/pen/abjqXbV However, ...

Instructions for transforming DOM information into a JSON format

I have multiple inputs within my document, as shown in the code snippet below. My goal is to create a string or JSON object using the input names and values. var arr= []; $('ul li input').each(function(){ let name = $(this).attr(' ...

Why isn't this setState function activating?

I am working on creating a versatile notification React component for my application that can be accessed from any part of the code. I have written the following code, where I am attempting to find a workaround for exporting the showNotif function: func ...

What is the reason for using a callback as a condition in the ternary operator for the Material UI Dialog component?

I am in the process of reconstructing the Material UI Customized Dialog component based on the instructions provided in this particular section of the documentation. However, I am unable to grasp the purpose behind using a callback function onClose conditi ...

inconsistent firing of mousedown events

On my webpage, I am using the following JavaScript code: $("#attach-body").mousedown(function (event) { //alert(event.button); switch (event.button) { case 2: event.preventDefault(); event.stopPropagation(); break; default: ...

Trouble with setInterval not refreshing the HTML element

I'm currently working on a script that should update the value of an element every second. However, I've encountered an issue where the element only updates the first time and then stops. Strangely, there are no errors appearing in the console ei ...

Creating .ipa Files with React Native

Is there a way to generate .ipa files in React Native for iOS without using XCode or an Apple Developer Account? Many references have not been successful in helping me achieve this. I attempted to build from XCode, but encountered issues with provisi ...

Retrieve the most recent item inside a div using JQuery

Is there a way to use jQuery to target the most recent element within this div that has the class name trackon? (such as #trackline1) Thanks! ...

Steps to animate a div expanding to fit its content dimensions

I'm looking for a way to animate the opening of a div so that it adjusts to the size of its content. The content is fetched from a separate search using .load, which means it could be just a single line (no result) or multiple results that vary in hei ...

Vue router beforeRouteEnter - when the page is refreshed, the button label vanishes

<script> export default { name: 'TEST', data() { return { prevRoute: '' } }, methods: { goBack() { return this.$router.go(-1); }, }, beforeRouteEnter(to, from, next) { next(vm => { ...

Best practices for integrating Vuex with Vuelidation

Currently, I am developing a Vue front end for an application that necessitates storing all form data locally before sending it to the backend in case of any network connectivity issues. To achieve this, I am using Vuex to manage and retain all the necessa ...

optimal application of css with jquery

I have a question about using jQuery to set the padding of a class or id. I am able to successfully change the height of an element with this code: $('.menu').css({ height: '90px' }); But now, I need to apply a specific CSS rule in jQ ...

Achieve Efficient Data Input in Django with JQuery Ajax for Multiple Forms

I am interested in carrying out a task similar to the one demonstrated in this video: https://youtu.be/NoAdMtqtrTA?t=2156 The task involves adding multiple rows to a table and then inserting them all into the database in a batch. Any references or sample ...

When is the best time to assign properties to mobx domain objects?

When it comes to tackling a specific problem in my react/mobx application, I'm facing challenges finding an optimal solution. Imagine having multiple boxes that need to be positioned on the screen based on various factors such as interdependency betwe ...

The extent of the modal window (AngularJS directive)

I've been experimenting with a modal window feature using Angular UI Bootstrap. Within the parent controller, I've defined the following function: $scope.open = function () { var modalInstance = $modal.open({ templateUr ...