gpt4 book ai didi

javascript - 在元素离开鼠标指针后移除悬停效果

转载 作者:可可西里 更新时间:2023-11-01 13:29:29 24 4
gpt4 key购买 nike

我正在尝试制作一些动画效果,单击时菜单按钮会分成三个子菜单。我在这方面面临 2 个问题:

  1. 子菜单图标与菜单图标重叠,然后开始移动。这是 因为我以这种方式保留了 JS 代码,因为最近,我 想要显示子菜单图标的移动。我知道原因 但无法修复它。

  2. 当点击菜单图标时,第三个子菜单的悬停效果仍然存在,只有在鼠标移动后才会消失微微一动。发生这种情况是因为它的初始位置是单击鼠标。我想不通,如何防止这件事免于发生。

HTML:

<ul class="list-inline">
<li class="text-center admin-menu-item">
<a id="applicationMenuBtn" class="User admin-menu-btn animates">
<i class="app-master-data-icon admin-icon"></i><br />
Application Master Data
</a>
<div class="dashboard-submenu-wrapper animates" id="applicationMenu">
<a href="#/manageApplicationUser" class="dashboard-submenu-item dashboard-submenu-item-one animates">
<i class="users-icon admin-sub-icon"></i><br />
Users
</a>
<a href="#/manageProjects" class="dashboard-submenu-item dashboard-submenu-item-two animates">
<i class="users-icon admin-sub-icon"></i><br />
Create Project
</a>
<a href="#/manageUserMapping" class="dashboard-submenu-item dashboard-submenu-item-three animates">
<i class="users-icon admin-sub-icon"></i><br />
User Mapping
</a>
</div>
</li>
</ul>

<div class="overlay"></div>

JS:

$(document).ready(function(){
$("#applicationMenuBtn").on('click', function(){
var parentLi = $(this).parents('li');
var adminMenu = parentLi.find('>div');
var adminMenuBtn = parentLi.find('>a');
adminMenuBtn.addClass('admin-menu-btn-animate').removeClass('admin-menu-reset');
adminMenu.show().addClass('submenu-visible');
$(".overlay").fadeIn();
adminMenu.find('.dashboard-submenu-item-one').css('transform', 'translate(135%, -100%)');
adminMenu.find('.dashboard-submenu-item-two').css('transform', 'translate(100%, 0)');
adminMenu.find('.dashboard-submenu-item-three').css('transform', 'translate(54%, 100%)');
});

$(".overlay").on('click', function(){
$(".overlay").fadeOut();
$('.submenu-visible').fadeOut(200).removeClass('submenu-visible');
$('.admin-menu-btn').removeClass('admin-menu-btn-animate').addClass('admin-menu-reset');
$('.dashboard-submenu-item-one, .dashboard-submenu-item-two, .dashboard-submenu-item-three').css('transform', 'translate(0, 0)');
});
});

CSS:

.overlay {
position: fixed;
display: none;
background-color: rgba(0, 0, 0, 0);
top: 0;
left: 0;
bottom: 0;
right: 0;
}

.admin-menu-item {
width: 150px;
float: left;
height: 100px;
margin: 40px 14px;
position: relative;
}

.admin-menu-item a {
display: inline-block;
text-decoration: none;
font-size: 16px;
color: #E50654;
}
.admin-icon {
background-repeat: no-repeat;
height: 100px;
width: 100px;
display: inline-block;
background-position: 13px 15px;
}

.admin-sub-icon {
background-repeat: no-repeat;
background-size: contain;
display: inline-block;
background-position: 0;
}

.app-master-data-icon,
.users-icon {
background-image: url("http://www.icosy.com/images/icons/career_icon.png");
}
.admin-menu-item .dashboard-submenu-item i {
width: 50px;
height: 50px;
line-height: 45px;
}
.dashboard-submenu-wrapper {
display: none;
z-index: 2;
}

.dashboard-submenu-item {
display: inline-block;
position: absolute;
top: 33%;
left: 17%;
z-index: 2;
color: #e50654;
transform: translate(0%, 0%);
}

.dashboard-submenu-item:hover {
color: blue;
}

.admin-menu-btn-animate {
transform: scale(0.8) translateX(-20%) translateY(-5%);
-ms-transform: scale(0.8) translateX(-20%) translateY(-5%); /* IE 9 */
-webkit-transform: scale(0.8) translateX(-20%) translateY(-5%); /* Chrome, Safari, Opera */
}

.admin-menu-reset {
transform: scale(1);
-ms-transform: scale(1);
-webkit-transform: scale(1);
transform: translateX(0);
}

.animates {
-webkit-transition: 0.25s ease-in-out;
-moz-transition: 0.25s ease-in-out;
-o-transition: 0.25s ease-in-out;
transition: 0.25s ease-in-out;
}

这是 Fiddle

最佳答案

发表我的评论作为答案,

这里的解决方法是在每个过渡事件上调整 z-index。

Updated Fiddle

注意下面的 CSS 变化

.hoverTweak{    //new class
z-index: 2 !important;
}

.dashboard-submenu-item {
display: inline-block;
position: absolute;
top: 33%;
left: 17%;
z-index: 0; //change
color: #e50654;
transform: translate(0%, 0%);
}

关于javascript - 在元素离开鼠标指针后移除悬停效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32325783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com