I am struggling with the layout of my webpage, which consists of 3 main div elements.
https://jsfiddle.net/wpztofb7/
<body>
<div id="topBox" class="otherBox">
TEST TOP
</div>
<div id="middleBox" class="middleBox">
SECTION
</div>
<div id="tab" class="tab"><span>New Comment</span></div>
<div id="bottomBox" class="otherBox">
TEST BOTTOM
</div>
</body>
.otherBox {
border: 2px solid #73AD21;
width: 100%;
height: 150px;
}
.middleBox {
border: 2px solid #73AD21;
width: 100%;
height: 25px;
}
.tab {
border-left: 2px solid #73AD21;
border-right: 2px solid #73AD21;
border-bottom: 2px solid #73AD21;
border-bottom-left-radius: 0.5em;
border-bottom-right-radius: 0.5em;
height: 15px;
width: 120px;
margin-bottom: 20px;
}
$(document).ready(function() {
click = 0;
$("#tab, #middleBox").click(function() {
if (click === 0) {
click = 1;
$("#middleBox").animate({
height: '400px'
}, 500);
} else {
click = 0;
$("#middleBox").animate({
height: '30px'
}, 850);
};
});
if (click === 0) {
//Do wiggle
$("#tab, #middleBox").mouseenter(function() {
$("#middleBox").animate({
height: "40px"
}, 800);
});
$("#middleBox").mouseleave(function() {
$("#middleBox").animate({
height: "30px"
}, 800);
});
}
});
The configuration of the middle div and tab elements is causing a problem for me. The objective is to have the middle div expand when clicked, while also providing a "wiggle" animation on mouse enter/leave to draw user attention.
Unfortunately, there is an issue when moving the mouse inside the expanded div after clicking it. Any movement collapses the div. I seek guidance on how to resolve this problem since I'm relatively new to web development.
I attempted using the .off("mouseenter mouseleave") method on the elements but to no avail.
Ultimately, I want users to be able to trigger the "wiggle" animation by hovering over the tab or div. If they click in the tab or div, the expansion animation should occur and persist until another click, even during mouse movement.