There seems to be a situation where multiple events are being queued up, creating a loop that continues until the mouse is moved. This issue persists even when using mouseenter instead of mouseover.
To address this, you can implement gatekeeper variables in your open and close routines to prevent multiple opens or closes. The gatekeeper variable should be unset in the complete
parameter of the animate
function.
openSideBar: function() {
if (!this.opening) {
this.opening = true;
$("#custom-erp-id-side-nav")
.off()
.animate({
left: "0px"
}, null, null, () => {
this.opening = false;
});
}
},
closeSideBar: function() {
if (!this.closing) {
this.closing = true;
$("#custom-erp-id-side-nav")
.off()
.animate({
left: "-230px"
}, null, null, () => {
this.closing = false;
});
}
}
// vue instance for the sidebar menu
var erp_custom_side_bar = new Vue({
el: "#custom-erp-id-side-nav",
data: {},
methods: {
//function to close/open the child elements
//when the parent menu is clicked.
toggleOpenChild: function(event) {
var currentParent = $(event.currentTarget)
.find(".custom-erp-menu-parent")
.text();
var childListID = currentParent.toLowerCase().replace(/ /g, "-");
$(".custom-erp-menu-list > ul")
.not($("#" + childListID + "-child"))
.slideUp()
.removeClass("custom-erp-menu-child-open");
if ($("#" + childListID + "-child").is(":hidden")) {
$("#" + childListID + "-child")
.slideDown(300)
.toggleClass("custom-erp-menu-child-open");
} else {
$("#" + childListID + "-child")
.slideUp(300)
.toggleClass("custom-erp-menu-child-open");
}
},
openSideBar: function() {
if (!this.opening) {
this.opening = true;
$("#custom-erp-id-side-nav")
.off()
.animate({
left: "0px"
}, null, null, () => {
this.opening = false;
});
}
},
closeSideBar: function() {
if (!this.closing) {
this.closing = true;
$("#custom-erp-id-side-nav")
.off()
.animate({
left: "-230px"
}, null, null, () => {
this.closing = false;
});
}
}
}
});
.custom-erp-side-nav {
height: 100%;
width: 240px;
position: fixed;
z-index: 1;
top: 56px;
left: 0;
background-color: #2b333e;
overflow-x: hidden;
padding-top: 20px;
left: -230px;
}
.custom-erp-side-nav-open {
left: 0;
}
.custom-erp-menu-list a {
padding: 10px 5px 10px 40px;
text-decoration: none;
letter-spacing: 0.3px;
font-size: 16px;
color: #aeb7c2;
display: block;
}
.custom-erp-menu-list>a {
padding-left: 20px;
}
.custom-erp-menu-list a:hover {
color: #f1f1f1 !important;
background-color: rgb(56, 65, 74);
}
.custom-erp-menu-list a:hover .custom-erp-module-list-icon {
filter: brightness(0) invert(1);
}
.custom-erp-module-list-icon {
margin-right: 10px;
}
.custom-erp-menu-child-dropdown {
display: none;
background-color: #252c35;
border-left: 3px solid #3cabfe;
}
.custom-erp-menu-child-dropdown>a:hover {
background-color: rgb(56, 65, 74);
}
#custom-erp-menu-lists {
padding-left: 0px !important;
}
.custom-erp-menu-child-open {
display: block;
}
<script src="https://unpkg.com/vue@latest/dist/vue.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="custom-erp-id-side-nav" class="custom-erp-side-nav" @mouseover="openSideBar" @mouseleave="closeSideBar">
<nav id="custom-erp-menu-nav">
<ul id="custom-erp-menu-lists">
<li class="custom-erp-menu-list" v-on:click="toggleOpenChild">
<a href="#">
<span>
<img src="assets/images/dollar-bills.svg" class="custom-erp-module-list-icon custom-erp-user-icons" width="18" height="18" alt="">
</span>
<span class="custom-erp-menu-parent">Purchase Order</span>
</a>
<ul class="nav custom-erp-menu-child-dropdown" id="purchase-order-child">
<li><a href="page-profile.html" class="custom-erp-menu-child">Profile</a></li>
<li><a href="page-login.html" class="custom-erp-menu-child">Login</a></li>
<li><a href="page-lockscreen.html" class="custom-erp-menu-child">Lockscreen</a></li>
</ul>
</li>
<li class="custom-erp-menu-list" v-on:click="toggleOpenChild">
<a href="#">
<span>
<img src="assets/images/dollar-bills.svg" class="custom-erp-module-list-icon custom-erp-user-icons" width="18" height="18" alt="">
</span>
<span class="custom-erp-menu-parent">Expense</span>
</a>
<ul class="nav custom-erp-menu-child-dropdown" id="expense-child">
<li><a href="page-profile.html" class="custom-erp-menu-child">Profile</a></li>
<li><a href="page-login.html" class="custom-erp-menu-child">Login</a></li>
<li><a href="page-lockscreen.html" class="custom-erp-menu-child">Lockscreen</a></li>
</ul>
</li>
</ul>
</nav>
</div>