Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8928279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:24:04+00:00 2026-06-15T08:24:04+00:00

I have this div that can be dragged vertically off the screen. I want

  • 0

I have this div that can be dragged vertically off the screen. I want to know if there’s a way to detect if that div has reached passed a certain limit, then display an animation where it automatically slides off the page. What I have done so far I thought should work, but alas, my mediocre knowledge of JavaScript has reared it’s ugly end. Here’s what I have so far:

$(document).ready(function() {
    $("div").draggable({
       axis: "y", // vertical drag only
       drag: function(event, ui) { // THIS NEXT BLOCK JUST MAKES SURE IT WON'T DRAG OFF THE BOTTOM OF SCREEN
            if($(this).offset().top + $(this).outerHeight() > $(window).height()) {
                $(this).offset({"top": $(window).height() - $(this).outerHeight()});
                event.preventDefault();
            }
       }
    });

    if($("div").css("top") == "-340px") {
        $("div").animate({
            top: "-100%"
        });
    }
});

I know that the jQuery UI “Draggable” uses the property top because I looked in Google Chrome’s debugger tool and as I was dragging it dynamically inserts inline styles, and I read top: -(x)px; keep climbing while I was dragging the div. So, logically, I tested to see if it gets dragged pass -340px then just automatically drag it the rest of the way.

And also, if possible, I would like for the div to drop down (using revert?) if it doesn’t go past -340px, but that’s not a huge issue really.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:24:06+00:00Added an answer on June 15, 2026 at 8:24 am

    Your condition is not in the right place; you should make the verification once the Drag even is fired !

    See bellow the code here check if position is upper then 100 and fire the animation :

    <html>
    <head>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    </head>
    <body>
    <div id="draggable" class="ui-widget-content ui-draggable" style="position: relative;">
        <p>Drag me around</p>
    </div>
    <script>
    $(document).ready(function() {
        $("div").draggable({
           axis: "y", // vertical drag only
           drag: function(event, ui) { // THIS NEXT BLOCK JUST MAKES SURE IT WON'T DRAG OFF THE BOTTOM OF SCREEN
                if($(this).offset().top + $(this).outerHeight() > $(window).height()) {
                    $(this).offset({"top": $(window).height() - $(this).outerHeight()});
                    event.preventDefault();
                }
    
                 if(Number($("div").css("top").replace("px","")) > 100) {
                    $("div").animate({
                        top: "-100%"
                    });
                }
           }
        });
    });
    </script>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse a html content that have something like this: <div id=sometext>Lorem<br>
I have a div containing an image that can be dragged around inside the
I have 2 html elements, 1. <div class=drag>..example.jpg..</div> contains images that can be dragged/cloned/dropped.
I have a div that has background:transparent , along with border . Underneath this
i have this simple div that has some text in it , and this
I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
I have this CSS style that does a rounded corners for div border, but
I have a div that's set to overflow: auto; . This contents of this
I have a div that contains two other divs,, like this: ---------------------------- | |
Hi i have a div as like that This is Frame a div This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.