Last active
August 29, 2015 14:16
-
-
Save giacomopaita/c27bef84f5d042f7eef7 to your computer and use it in GitHub Desktop.
How to make show/hide a non-child <div> when mouseenter/leave on a link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[class*="strip-header"] { | |
width: 100%; | |
overflow: hidden; | |
} | |
* { | |
font-family:'Century Gothic'; | |
padding:0; | |
margin:0; | |
color:#E0B880 | |
} | |
a { | |
color: red; | |
} | |
.strip-header-submenu .submenu > a:hover { | |
color: #f4d007; | |
} | |
.main-menu > a:hover { | |
color: #f4d007; | |
} | |
.internal-links { | |
width: 116.979%; | |
} | |
.internal-links:before, internal-links:after { | |
content:" "; | |
display: table; | |
} | |
.internal-links:after { | |
clear: both; | |
} | |
.internal-links .link .icon-link { | |
opacity: 0; | |
filter: alpha(opacity=0); | |
} | |
.internal-links .link:hover .img { | |
height: 100%; | |
width: 120%; | |
left: -15%; | |
} | |
.internal-links .link:hover .inner-content { | |
top: 0; | |
height: 100%; | |
opacity: 1; | |
filter: alpha(opacity=100); | |
} | |
.internal-links .link:hover h3 { | |
top: -50px; | |
background-color: transparent; | |
} | |
.internal-links .link:hover .icon-link { | |
opacity: 1; | |
filter: alpha(opacity=100); | |
} | |
.page-container-header { | |
top: 0; | |
left: 0; | |
right: 0; | |
z-index: 3; | |
} | |
.strip-header-title { | |
background: #FFF; | |
height: 40px; | |
line-height: 40px; | |
} | |
.strip-header-title .content { | |
text-align: center; | |
} | |
.strip-header-menu { | |
background: #0071b9; | |
display: block; | |
-webkit-transition: all 0.2s ease 0; | |
-moz-transition: all 0.2s ease 0; | |
-o-transition: all 0.2s ease 0; | |
-ms-transition: all 0.2s ease 0; | |
transition: all 0.2s ease 0; | |
} | |
.strip-header-menu .content { | |
text-align: center; | |
} | |
.strip-header-menu.is-visible { | |
display: block; | |
} | |
.strip-header-submenu { | |
background: #F0E890; | |
text-align: center; | |
line-height: 28px; | |
position: relative; | |
height: 0; | |
visibility: visible; | |
-webkit-transition: all 0.2s ease 0; | |
-moz-transition: all 0.2s ease 0; | |
-o-transition: all 0.2s ease 0; | |
-ms-transition: all 0.2s ease 0; | |
transition: all 0.2s ease 0; | |
} | |
.strip-header-submenu.is-visible { | |
height: 28px; | |
} | |
.strip-header-submenu .submenu.is-visible { | |
top: 0; | |
} | |
.strip-header-submenu .submenu { | |
text-align: left; | |
top: -30px; | |
position: absolute; | |
-webkit-transition: all 0.2s ease 0; | |
-moz-transition: all 0.2s ease 0; | |
-o-transition: all 0.2s ease 0; | |
-ms-transition: all 0.2s ease 0; | |
transition: all 0.2s ease 0; | |
} | |
.strip-header-submenu .submenu > a { | |
color: #FFF; | |
text-decoration: none; | |
font-size: 0.875em; | |
-webkit-transition: all 0.2s ease 0; | |
-moz-transition: all 0.2s ease 0; | |
-o-transition: all 0.2s ease 0; | |
-ms-transition: all 0.2s ease 0; | |
transition: all 0.2s ease 0; | |
} | |
.strip-header-submenu .submenu > a.current { | |
color: #f4d007; | |
} | |
.strip-header-submenu .submenu > a + a { | |
margin-left: 35px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.main-menu a[data-section]').mouseenter(function () { | |
var selector = $(this).data('section'); | |
if (selector) { | |
var $submenu = $('.' + selector); | |
var visSub = $('.strip-header-submenu .submenu.is-visible').not($submenu); | |
if (visSub.length > 0) { | |
clearHideTimeout(visSub); | |
hideSubmenu(visSub); | |
} | |
clearHideTimeout($submenu); | |
$('.' + selector).addClass('is-visible').parent().addClass('is-visible'); | |
} | |
}) | |
.mouseleave(function () { | |
var selector = $(this).data('section'); | |
if (selector) { | |
setHideTimeout($('.' + selector)); | |
} | |
}); | |
$('.strip-header-submenu > div').mouseenter(function () { | |
var $t = $(this); | |
clearHideTimeout($t); | |
}) | |
.mouseleave(function () { | |
var $t = $(this); | |
clearHideTimeout($t); | |
setHideTimeout($t); | |
}); | |
function clearHideTimeout($ele) { | |
var $timer = $ele.data('timer'); | |
if ($timer) { | |
window.clearTimeout($timer); | |
} | |
} | |
function setHideTimeout($ele) { | |
var $timer = window.setTimeout(function () { | |
hideSubmenu($ele); | |
}, 500); | |
$ele.data('timer', $timer); | |
} | |
function hideSubmenu($ele) { | |
$ele.removeData('timer').removeClass('is-visible') | |
.parent().removeClass('is-visible'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="strip-header-title"> | |
<div class="content"> | |
<h1 class="main-logo"><a href="#1">MY SITE TITLE</a></h1> | |
</div> | |
</div> | |
<div class="strip-header-menu"> | |
<div class="content"> | |
<div class="main-menu"> <a data-section="" href="#1">First Link</a> | |
<a data-section="working-link" href="#2">Working Link</a> | |
<a data-section="should-working-link" href="#3">Should Working Link</a> | |
<a data-section="" href="#4">Other Link</a> | |
</div> | |
</div> | |
</div> | |
<div class="strip-header-submenu"> | |
<div class="submenu first-sub"> <a href="#1">a. First Link</a> | |
<a href="#2">b. First Link</a> | |
<a href="#3">c. First Link</a> | |
</div> | |
<div class="submenu working-link"> <a href="#1">a. working-link</a> | |
<a href="#2">b. working-link</a> | |
<a href="#3">c. working-link</a> | |
</div> | |
<div class="submenu should-working-link"> <a href="#1">should-working-link</a> | |
<a href="#2">should-working-link</a> | |
<a href="#3">should-working-link</a> | |
</div> | |
<div class="submenu last-sub"> <a href="#1">Other Link</a> | |
<a href="#2">Other Linkk</a> | |
<a href="#3">Other Link</a> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment