jQuery draggable - element moving beyond the boundaries of the container in Chrome and Safari

Take a look at this code :

HTML

<div class="draggable_main_container">
    <div class="draggable_container">
        <div class="draggable">
            <div class="minus">
                label
            </div>
        </div>
    </div>
</div>

CSS

.draggable_main_container
{
    width:134px;
    overflow:auto;
    position:relative;
    height:350px;
}

.draggable_container
{
    height:300px;
    position:relative;
    overflow:visible; 
    background-color:blue;  
}

.draggable
{           
    background-color:red;
    height:134px;
    width:134px;
    cursor:pointer;
    position:relative;
}

.draggable .minus
{
    position:absolute;
    left:50px;
    bottom:-20px;    
    width:32px;
    height:20px;  
    background-color:yellow;  
}

jQuery

$(".draggable").draggable({
    axis: "y",
    containment: 'parent'
});

In Firefox, everything runs smoothly. However, in Chrome and Safari, there seems to be an issue when the draggable element reaches the bottom of the container.

If I click and scroll back down again, the div moves beyond the container's boundaries. This results in scroll bars appearing once the main container's height (350px) is reached.

To prevent the appearance of scroll bars, adding overflow:visible; to draggable_main_container is a quick fix.

But what I really need is for the draggable element to stop moving when it reaches the bottom of its parent container. How can I achieve this?

I suspect that the culprit might be the absolute positioning of the .minus element attached to the draggable item. Removing it seems to resolve the problem...

Answer №1

After experimenting with your code, I made a discovery and found a solution.

Currently, the draggable element is constrained by its parent .draggable_container. However, there is a slight issue with the minus element protruding outside of the .draggable_container when dragged. This causes the parent element to temporarily increase in size, allowing for further scrolling. The fix for this is to add 20px of padding to the bottom of .draggable_container to prevent the minus element from extending beyond it.

It's unclear why this only occurs when clicked, but adding padding resolves the issue.

Although this may remove the effect of the "label" going outside the blue box, there are alternative methods to achieve a similar visual outcome.

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

Display a popup div while communicating with an AJAX server

As I work on my website's interaction with my AJAX server, I am looking to display a central popup on the screen. Since some tasks take a few seconds to complete, I want to visually indicate to users that an operation is in progress. For example, cons ...

Activate Bootply libraries with Bootstrap data toggle tab

Greetings! I am excited to be sharing my first post here and although I am a newcomer, I am eager to expand my knowledge. Before reaching out with my question, I did some research here because I found myself a bit stuck. Allow me to provide an example of ...

Creating a CSS animation that smoothly slides across the screen and unveils a hidden text/div once the animation is complete

I have been attempting to replicate the captivating CSS animations seen on a particular website: My goal is to imitate how the site: initially reveals a full-screen black div sliding away to the right progressively loads the black background (div ta ...

The pause button will still function, even if the scrolling feature is enabled

I've successfully implemented a feature that pauses and plays the video on scroll when it reaches a certain pixel height. However, I'm facing an issue where the code automatically plays the video whenever the scroll position is more than 13500px ...

Bootstrap popover fails to function without any visible errors

Currently in the process of developing a website with the latest version of Bootstrap, I'm looking to implement a feature where a popover appears upon clicking a specific button. After including the necessary jQuery and popper.js files in my project, ...

What are the steps to resolve an undefined variable error in PHP?

I have a webpage named index.php. This page is designed to implement infinite scrolling using AJAX, PHP, and MySQL. The PHP MySQL codes are located at the top while JavaScript is placed at the bottom. I am trying to display the total number of rows in th ...

Validating Captcha with jQuery and AJAX for Securimage

I have gone through numerous questions and tutorials, but no matter what I try, I can't seem to get it to work. Here is the HTML code for my login page (/login.php) <form action="func/login.php" method="post" name="login"> ...

What is the best way to achieve a consistent style for two tables?

I would like to achieve uniform styling for each row. The first row, which contains 'het regent vandaag', has the following CSS rule: .attachments-table td { margin: 0 5px; padding: 10px 8px; line-height: 1.4; white-space: pre-wr ...

When I try to add more content to my page, it doesn't extend beyond a single page and instead gets compacted together

As a beginner in the world of coding, my goal is to create a time management website specifically tailored for school use. Despite copying this code multiple times, I have encountered an issue where it does not continue down the page, and I am unsure of th ...

Can you explain the distinction between a block-level box and a primary block-level box?

According to the specification: Block-level boxes are defined as those participating in a block formatting context. Each block-level element generates a primary block-level box that contains descendant boxes and generated content, serving as the k ...

Tips for keeping the background image anchored to the bottom of your browser

I am looking to make sure that the footer image on my website remains at the bottom of the browser when the page content is short. The CSS code currently being used for this is: #site-container {width:100%; background:url(.../site-bg-foot.jpg) no-repeat ...

Issue with displaying background image in mobile device despite successful display in browser and Chrome tools on Angular 18

Revamping my personal website (www.coltstreet.com) led me to explore media queries for displaying different background images. Testing on desktop and via Chrome tools showed positive results, but the real challenge arose when viewing the site on my actual ...

Enhancing a class's properties from its parent component using React

Recently, I decided to dive into React by taking on the challenge of rebuilding the Google Weather app. My main objective is to have the main section update whenever a day is selected. Initially, I believed that updating the props within handleSelectionAt( ...

Firefox doesn't support CSS bubble functionality

Here is the CSS code I am using: .bubbledLeft, .bubbledRight{ position: relative; margin-top: 3px; max-width: 99%; clear: both; min-width: 99%; } .bubbledLeft{ float: left; margin-right: auto; padding: 14px 10px 4px 15 ...

Converting canvas illustrations into HTML files

I am in the process of creating a drawing application that will be able to export into HTML/CSS/JavaScript. I plan to use this tutorial as a foundation for the drawing functionality. My goal is to take all the rectangles within the this.shapes = [] array a ...

The functionality of the right property is not functioning properly when used in conjunction

One may wonder why, even though the right property is set to 0, the child div appears aligned with the left side instead of being on the right side of its parent div. div.relative { position: relative; width: 400px; height: 200px; border: 3px so ...

What is the best way to activate Cropper once a file has been selected, without encountering a 404 error on the image?

I've been trying to integrate an image cropper into my website, but I'm encountering some issues that I can't seem to resolve. Expected outcome : Upon selecting a picture from the disk using the file input, a modal should appear prompting t ...

An issue has occurred: The column name 'B' is not valid. This error originated from the System.Data.SqlClient.SqlConnection

I'm currently working on developing a straightforward registration page using ASP.NET C# in Visual Studio 2013. After attempting to submit the registration details for database insertion purposes, an error occurred. The error message indicated an iss ...

Continue to load additional elements using ajax in a loop until a specific element is located

I'm currently using an ajax function to continuously load the next page or results without having to refresh. It's working well, but my goal is to keep running this function in a loop until a specific element is loaded through the ajax call. Usi ...

A guide on dynamically adjusting image size in ReactJS

Here is the structure I have: img { width: auto; height: 200px; } .cards { display: flex; justify-content: center; margin-top: 2em; width: 80%; flex-wrap: wrap; } .card { margin: 1em; box-shadow: 0 0 6px #000; ...