Can the autoscroll offset be adjusted while dragging?

I am developing a single-page application using Vue.js. The user interface consists of three main components:

  • A fixed navbar at the top with a z-index of 2
  • A fixed sidebar on the left with a z-index of 1, and padding to accommodate the navbar
  • A central area with padding to account for the other fixed elements.

The sidebar is scrollable with overflow-y: auto. Certain items within the sidebar, referred to as "item X" here, are draggable.

Typically, when moving towards the edges of a scrollable area while dragging, the area will automatically scroll in that direction. However, in my app, the sidebar does not autoscroll because its upper edge is covered by the navbar.

One solution could involve restructuring the sidebar so that its upper edge is visible instead of being hidden beneath a padded div. However, this approach may have unintended consequences.

Question: I would like to explore methods for triggering auto-scroll during drag when the mouse is close to the edge, perhaps within $navbarHeight pixels.

I am seeking a solution that is pure HTML5, vanilla JavaScript, or compatible with my current framework (Vue.js v3).

What I have attempted: Despite extensive research, keywords such as "auto scroll while dragging," "scroll sensitivity area," and "autoscroll offset" have not provided relevant insights.

JS Fiddle: https://jsfiddle.net/7f5wh1mj/4/

Visual Representation: Please refer to the fiddle for a live demonstration.

Answer №1

In today's world, grid layouts can be used to create unique designs. Here is an example that demonstrates how to achieve a layout using grid without relying on position properties.

new Vue({
  el: "#app",
  data: {
    todos: [{
        text: "Learn JavaScript",
        done: false
      },
      {
        text: "Learn Vue",
        done: false
      },
      {
        text: "Play around in JSFiddle",
        done: true
      },
      {
        text: "Build something awesome",
        done: true
      }
    ],
    items: 12
  },
  methods: {
    toggle: function(todo) {
      todo.done = !todo.done
    }
  }
})
* {
  box-sizing: border-box;
}

body {
  background: #20262E;
  font-family: Helvetica;
  overflow: hidden;
  margin: 0;
  height: 100vh;
  width: 100vw;
}

#app {
  background: #fff;
  display: grid;
  grid-template-columns: 150px 1fr;
  grid-template-rows: auto 1fr;
  height: 100%;
}

.navbar {
  grid-row: 1;
  grid-column: 1 / 3;
  padding: 0.5em;
  background-color: lightgreen;
}

.sidebar {
  background-color: lightgray;
  overflow-y: auto;
}

.content {
  background-color: #fff;
  overflow: auto;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

del {
  color: rgba(0, 0, 0, 0.3);
}

aside p {
  text-align: center;
  color: white;
  background: gray;
  position: sticky;
  top: 0;
  margin: 0;
  padding: 0.25em 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div class="navbar">
    <h1>Navbar</h1>
  </div>
  <aside class="sidebar">
    <p>Sidebar</p>
    <ul>
      <li draggable v-for="n in items">item {{ n }}</li>
    </ul>
  </aside>
  <div class="content">
    <h2>Todos:</h2>
    <ol>
      <li v-for="todo in todos">
        <label>
          <input type="checkbox" v-on:change="toggle(todo)" v-bind:checked="todo.done">

          <del v-if="todo.done">
            {{ todo.text }}
          </del>
          <span v-else>
            {{ todo.text }}
          </span>
        </label>
      </li>
    </ol>
  </div>
</div>

edit: A comment has been added along with an example of using the sticky position within the sidebar.

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

Using Javascript to Treat an HTML Document as a String

Check out the complete project on GitHub: https://github.com/sosophia10/TimeCapsule (refer to js/experience.js) I'm utilizing JQuery to develop "applications" for my website. I'm encountering a problem where I can't locate the correct synta ...

Having trouble reaching the vue binary through my command line interface

Encountering some difficulties while attempting to set up Vue CLI on my Mac. I prefer working with yarn instead of npm in the terminal. These are the commands I used: yarn global add @vue/cli Upon installation, a success message appeared in the terminal. ...

My goal is to create collapsible and expandable rows within this table

Discover the code snippet here, without pasting the entire content... As an illustration, let's utilize this example: <head> </head> <body> <table> <tr> <th></th> < ...

Can a CSS hover effect transition modify the color scheme?

I have multiple buttons on a single page, and I want the hover effect to be applied to all of them with just one code using jQuery. Please review my code below. $(document).ready(function(){ $('.button').hover(function(){ var bc=$(this ...

Trouble with variable in require path causing issues with r.js

As a newcomer to optimizing with r.js, I am also a big fan of requirejs build-config.js ({ appDir: "./src/main/webapp/webresources/javascript/", baseUrl: "./", dir: "./target/webresources/js", optimizeCss ...

Quasar - q-scroll-area : Allow child to fill the available space

Within my q-page, I have a q-card that consists of a q-scroll-area. There are two scenarios to consider: If the child is smaller than the parent (horizontally, vertically, or both), I want the child to expand and fill all available space. If the child is ...

Overlay with a progress bar that obscures visibility

I'm dealing with a progress bar that needs to be displayed on top of an overlay. If you take a look at this jsfiddle, you can see the issue. Here's the markup: <div class="overlay mouse-events-off"> <div class="progress progress-st ...

The HTML element in the side menu is not adjusting its size to fit the parent content

Update: What a day! Forgot to save my work... Here is the functioning example. Thank you for any assistance. I have set up a demo here of the issue I'm facing. I am utilizing this menu as the foundation for a page I am developing. The menu is built ...

What is the best way to utilize images stored in the public directory rather than the assets folder within my Vue application?

When including images from the assets folder (located in src besides App.vue), it builds and runs successfully. However, when attempting to change the image using JavaScript, it doesn't work as expected. For instance: background-image: url('../as ...

Encrypting data using JavaScript and then decrypting it with Ruby

Looking to securely encrypt a string in a client-side JavaScript application and decrypt it on a Ruby on Rails Server. Interested in utilizing AES for encryption. What would be the most effective combination of scripts, libraries, or methods to achieve t ...

Create a series of canvas lines connecting all divs that share a common class identifier

Currently, I am in the process of creating a document that will establish a tree-type graph based on user input. My goal is to link styled divs with canvas lines to show their connection to the parent div. I have been utilizing .getBoundingClientRect() to ...

Error encountered in AngularJS and JSON server: [$injector:unpr] An unidentified provider was found: $resourceProvider <- $resource <- menuFactory

Hello everyone, I recently created a small AngularJS application and utilized a JSON server for my backend operations. Unfortunately, I am encountering an issue with the provider in my code. Upon running it, I am receiving errors as shown below: Uncaugh ...

Leveraging the reset function with the $meteor.object

Currently, I am working on a straightforward controller utilizing the angular-meteor starter project. controller("PartyDetailsCtrl", function($scope, $stateParams, $meteor) { $scope.party = $meteor.object(Parties, $stateParams.partyId); $scope.save = ...

Issue with Typescript and react-create-app integration using Express

I'm relatively new to Typescript and I decided to kickstart a project using create-react-app. However, I encountered an issue while trying to connect my project to a server using express. After creating a folder named src/server/server.ts, React auto ...

Enhancing the mobile menu with a feature that allows users to easily close the

I am currently designing a mobile menu for a website that I created using Wordpress with the Divi Theme. When the user clicks on a "hamburger icon", it triggers a fullscreen menu to open: mobile menu If you tap on "Termine", it will reveal a submenu: mo ...

Executing Python code through a website using PHP - is there a way to deactivate the button once it has been clicked?

Can you assist with the following issue? <?php if(isset($_POST['MEASURE'])) { shell_exec("sudo python /var/www/html/lab/mkdir.py"); } ?> Here is the HTML part: <form method="post" > <input type="submi ...

How to customize the button color in a Next.js application

Help Needed: Issue with Changing Default Button Color in Next.JS Web Application. The button text color appears as grey on Desktop Google Chrome, but shows up as blue on Mobile Chrome browser. I want to unify the color to be grey on both platforms. Custo ...

Extracting public data from social media profiles as displayed in Smartr

Is there any pre-existing API or reference material available for achieving this task? I am interested in accessing public social data without the need for users to manually link their accounts to our site. ...

Uploading base64 arrays from AngularJS to a Node.js server: Allowing Access-Control-Origin

My current challenge involves sending an array of base64 strings from my Client Side (AngularJs) to my NodeJs Server. However, I've encountered a peculiar situation. When I attempt to send an object containing the base64 data along with other properti ...

Utilize Sass @extend to incorporate imported CSS files in the build process

In my development setup, I have a global CSS file that houses all of the generic CSS styles. My goal is to extend the classes from this global CSS file in any of my SCSS files. However, when I attempt to do so, I encounter an error stating that the .xyz c ...