I am currently working on a project that involves creating a div element for the purpose of dragging and dropping files. My goal is to have the height of the div increase when a file is dragged into it, and decrease when the file is dragged out.
To achieve this functionality, I have implemented event listeners for the 'ondragover' and 'ondragleave' events, along with utilizing the .css() function to adjust the height of the div. While everything works as intended using the .css() function, I encountered unexpected behavior when attempting to use the .animate() function. When dragging over the div, the height increases as expected, but if the file is then dragged out without being dropped, the height does not decrease as desired.
Feel free to experiment below by dragging a file in and out of the div without actually dropping it:
function enter_drop(){
$("#box").animate({height: "300px"}, 500);
}
function leave_drop(){
$("#box").animate({height: "100px"}, 500);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="box" style="background:#98bf21;height:100px;width:100px;margin:6px;float:left" ondragover="enter_drop()" ondragleave="leave_drop()"></div>
<img id="drag1" src="http://cdn.sstatic.net/Sites/stackoverflow/img/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="234253534f460e574c56404b0e4a404c4d63110d534d44">[email protected]</a>" draggable="true" style="float:left">