我有一个悬停方法,它似乎仅在移动设备上的第一次通过时有效;在台式机上就可以了。
这是一个演示:
这是jQuery代码:
$(document).ready(function() {
var $subnav = $('.subnav');
$(".close").on('click tap', function(e) {
if ($subnav) $subnav.hide();
else $subnav.show();
});
$(".discover, .watch").hover(
function(e) {
$(this).find($subnav).show();
},
function() {
$(this).find($subnav).hide();
}
);
});
$(document).ready(function() {
var $subnav = $('.subnav');
$(".close").on('click tap', function(e) {
if ($subnav) $subnav.hide();
else $subnav.show();
});
$(".discover, .watch").hover(
function(e) {
$(this).find($subnav).show();
},
function() {
$(this).find($subnav).hide();
}
);
});
/* Header / Nav Section */
main {
width: 100%;
height: 100%;
overflow-x: hidden;
}
header.navbar {
position: fixed;
top: 0;
max-width: 1800px;
margin: 0 auto;
background-color: #000;
}
header .header {
height: 58px;
position: relative;
}
header .globalLogo img {
width: 128px;
height: 100%;
display: inline-block;
position: absolute;
z-index: 350;
}
nav {
display: inline-block;
position: absolute;
width: 100%;
height: 100%;
left: 0;
text-align: center;
z-index: 300;
}
nav ul {
padding: 0;
margin: 0 auto;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
nav ul li {
font-family: Brown Bold, sans-serif;
font-size: 14px;
letter-spacing: .1em;
line-height: 1.2em;
word-spacing: normal;
font-weight: 400;
text-transform: uppercase;
letter-spacing: .2em;
color: #fff;
display: inline-block;
list-style: none;
text-align: left;
}
header nav ul:not(:hover).discover-active .discover .nav-category {
color: #ef4b4b;
}
nav ul li .nav-category {
padding: 0 15px 0 30px;
height: 58px;
position: relative;
}
nav ul:not(:hover).discover-active .discover .nav-category:before {
background-color: #ef4b4b;
content: "";
position: absolute;
left: 0;
height: 4px;
width: 100%;
}
header nav .nav-categories .nav-category-and-subnav.discover:hover .nav-category:before {
background-color: #ef4b4b;
content: "";
position: absolute;
left: 0;
height: 4px;
width: 100%;
}
header nav .nav-categories .nav-category-and-subnav.watch:hover .nav-category:before {
background-color: #e5059a;
content: "";
position: absolute;
left: 0;
height: 4px;
width: 100%;
}
.discover .subnav,
.watch .subnav,
.global-site-switch .subnav {
display: none;
}
.discover .subnav img {
width: 100%;
}
header nav .nav-categories .nav-category-and-subnav.discover .subnav {
background-color: #000;
position: fixed;
left: 0;
right: 0;
margin: 0 auto;
top: 59px;
height: 530px;
width: 635px;
z-index: 1000;
}
header nav .nav-categories .nav-category-and-subnav.watch .subnav {
background-color: #000;
position: fixed;
left: 0;
right: 0;
margin: 0 auto;
top: 59px;
height: 530px;
width: 635px;
z-index: 1000;
}
header .global-site-switch:hover .subnav {
background-color: #000;
position: absolute;
display: block;
padding: 0px;
left: -30px;
top: 47px;
height: 120px;
width: 120px;
}
nav ul li .nav-category .nav-category-padding {
position: relative;
top: 17px;
}
nav ul li .nav-category .fa-angle-down {
position: relative;
top: 20px;
margin-left: 6px;
width: auto;
color: #fff;
opacity: .4;
font-size: 18px;
text-align: right;
max-width: 18px;
}
header div.header .global-site-switch {
position: absolute;
width: 70px;
height: 48px;
top: 12px;
right: 60px;
padding: 0 10px;
text-align: center;
color: #fff;
z-index: 350;
}
header .global-site-switch .subnav a:hover {
text-decoration: none;
color: #fff;
}
header .global-site-switch .subnav a img {
width: 25px;
margin: -3px 10px 0 0;
}
header .global-site-switch .subnav a span {
text-transform: uppercase;
font-family: Brown Bold, sans-serif;
color: #fff;
}
header div.header .global-site-switch .country {
display: inline-block;
height: 30px;
vertical-align: middle;
}
header div.header .global-site-switch .country img {
vertical-align: middle;
/* height: 14px; */
height: 30px;
width: auto;
padding: 8px 5px;
}
header div.header .global-site-switch .fa {
font-size: 12px;
font-weight: 800;
height: 12px;
width: 11px;
}
header div.header .global-site-switch .label {
font-family: Brown Regular, sans-serif;
font-size: 10px;
letter-spacing: .05em;
line-height: 1.3em;
word-spacing: normal;
text-transform: uppercase;
font-style: italic;
display: inline-block;
}
header div.header .global-site-switch ul li {
list-style: none;
margin: 5px 0;
}
header .global-search-nav.active .search-drawer,
header .global-search-nav.active .search-drawer #search-header,
header .global-search-nav.active .search-drawer .search-close {
display: inline-block;
}
header .global-search-nav {
display: block;
margin: auto;
top: -58px;
right: 0;
position: relative;
max-width: 1100px;
z-index: 350;
}
header .global-search-nav.active {
width: 100%;
height: 100%;
background-color: #fff;
position: absolute;
z-index: 375;
max-width: 100%;
top: 0;
}
header .global-search-nav .search-button {
position: absolute;
margin: auto;
top: 0;
right: 0;
height: 50%;
width: 20px;
z-index: 375;
}
header .global-search-nav.active .search-button {
display: none;
}
header .global-search-nav .search-button .fa-search {
position: absolute;
top: 17px;
right: 0;
font-size: 22px;
height: 22px;
color: #fff;
cursor: pointer;
}
header .global-search-nav .search-drawer {
display: none;
position: absolute;
margin: auto;
top: 0;
right: 0;
left: 0;
height: 100%;
max-width: 1100px;
background: #fff;
z-index: 375;
}
header .global-search-nav .search-drawer form {
height: 100%;
width: 100%;
}
header .global-search-nav .search-drawer #search-header {
font-family: Playfair Display, serif;
font-size: 22px;
font-weight: 700;
word-spacing: normal;
letter-spacing: -.02em;
line-height: 1.3em;
text-transform: none;
font-weight: 400;
width: 100%;
height: 100%;
margin: 0;
padding: 0 50px;
text-align: center;
border: 0;
outline: none;
box-shadow: none;
color: transparent;
display: inline-block;
text-shadow: 0 0 0 #000;
&:focus {
outline: none;
}
}
header .global-search-nav .search-drawer .search-close {
display: none;
position: absolute;
top: 20px;
right: 0;
cursor: pointer;
height: 20px;
width: 20px;
background-image: url(/images/close.svg);
background-size: contain;
background-repeat: no-repeat;
background-position: 50%;
color: #000;
}
/* Header */
@media only screen and (max-width: 760.98px) {
header.navbar {
background-color: #fff;
}
header.navbar div.header {
padding-left: 20px;
padding-right: 20px;
height: 38px;
}
header.navbar div.header .global-site-switch {
color: #000;
top: 3px;
}
header.navbar div.header .global-site-switch:hover .subnav {
top: 30px;
height: 142px;
padding: 14px 0;
}
header.navbar div.header .global-search-nav {
top: -38px;
}
header .global-search-nav .search-button .fa-search {
top: 28px;
right: 25px;
font-size: 16px;
height: 16px;
color: #000;
}
header.navbar div.header nav {
display: block;
position: fixed;
left: 0;
width: 100%;
background: #000;
border-top: 4px solid #fff;
height: 45px;
top: 38px;
}
header.navbar div.header .nav-categories .nav-category-and-subnav.discover:hover .nav-category:before,
header.navbar div.header .nav-categories:not(:hover).discover-active .discover .nav-category:before,
header.navbar div.header .nav-categories .nav-category-and-subnav.watch:hover .nav-category:before {
top: -4px;
}
header.navbar div.header nav .nav-categories .nav-category-and-subnav:hover .subnav {
top: 83px;
width: 100%;
}
header.navbar div.header .nav-categories .nav-category-and-subnav {
font-size: 13px;
letter-spacing: .1em;
line-height: 1.2em;
word-spacing: normal;
font-weight: 400;
text-transform: uppercase;
letter-spacing: .2em;
display: table-cell;
width: 1%;
}
header.navbar div.header .nav-categories .nav-category-and-subnav .nav-category .nav-category-padding {
font-size: 12px;
top: 11px;
}
header.navbar div.header .nav-categories .nav-category-and-subnav .nav-category i.fa {
height: 14px;
}
header.navbar div.header .nav-categories .nav-category-and-subnav .nav-category .fa-angle-down {
top: 13px;
margin-left: 3px;
font-size: 13px;
}
header .global-search-nav.active .search-drawer,
header .global-search-nav.active {
height: 42px;
}
header .global-search-nav .search-drawer .search-close {
right: 20px;
top: 12px;
height: 18px;
width: 18px;
}
p.close {
margin: 10px;
}
}
@media only screen and (min-width: 1221px) {
header .header {
max-width: 1100px;
margin: 0 auto;
}
header nav .nav-categories {
max-width: 535px;
}
}
@media only screen and (max-width: 1220.98px) and (min-width: 761px) {
header .globalLogo img {
height: 50px;
}
header .header {
padding-left: 30px;
padding-right: 30px;
}
header nav .nav-categories {
max-width: 403px;
}
nav ul li .nav-category .nav-category-padding {
top: 15px;
}
nav ul li .nav-category .fa-angle-down {
margin-left: 3px;
top: 18px;
}
header .global-site-switch {
right: 80px;
}
header .global-search-nav .search-button {
right: 30px;
}
header .global-search-nav .search-drawer .search-close {
right: 30px;
}
}
@media only screen and (max-width: 1220.98px) {
nav ul li .nav-category {
padding: 0 5px 0 10px;
text-align: center;
}
}
/* Main */
@media only screen and (max-width:760.98px) {
.opener .full-width-opener {
position: relative;
}
.opener .full-width-opener:before {
display: block;
content: "";
width: 100%;
padding-top: 120%;
}
.opener .full-width-opener>.content {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.story-share.article-bottom {
width: 275px;
}
.r29-article .header .title {
font-family: Playfair Display, serif;
font-size: 25px;
font-weight: 700;
word-spacing: normal;
letter-spacing: -.02em;
line-height: 1.3em;
text-transform: none;
}
}
@media only screen and (min-width:761px) {
.story-share.article-bottom {
width: 165px;
}
.body .section-container.left-align {
float: left;
margin: 10px 20px 20px 0;
}
.body .section-container.right-align {
float: right;
margin: 10px 0 20px 20px;
}
.body .section-container.half-width {
width: 360px;
}
.body .section-container.half-width.left-align,
.body .section-container.half-width.right-align {
width: 340px;
}
.body .section-container.full-width {
width: 720px;
}
}
@media only screen and (max-width:1220.98px) {
.r29-article {
padding: 25px 12px 50px;
margin-top: 0;
}
.product-carousel {
width: 100%!important;
margin-top: 25px;
}
.product-carousel button.slick-arrow.slick-prev svg {
padding-left: 0;
}
}
@media only screen and (min-width:761px) and (max-width:1220.98px) {
.r29-article .header .title {
font-family: Playfair Display, serif;
font-size: 40px;
font-weight: 700;
word-spacing: normal;
letter-spacing: -.02em;
line-height: 1.3em;
text-transform: none;
}
.product-carousel .product-grid-header {
margin-bottom: 20px;
max-width: 720px;
}
}
@media only screen and (min-width:1221px) {
.body .section-container.section-asset-container {
margin: 48px auto;
}
.product-carousel .slick-list {
left: 12px;
}
}
/* Footer */
@media only screen and (max-width: 1220.98px) {
.global-footer .social-container .social-nav li+li {
margin-left: 12px
}
}
@media only screen and (min-width: 761px) {
.global-footer .social-container .social-nav li+li {
margin-left: 10.6px
}
}
@media only screen and (min-width: 761px) and (max-width:1220.98px) {
.global-footer .social-container {
display: block;
margin: 0 auto;
text-align: center
}
.global-footer .links {
width: 33%;
text-align: center;
margin: 40px 0
}
.global-footer .links ul li {
text-align: center
}
.global-footer .email-signup {
display: block;
margin: 0 auto
}
.global-footer .email-signup .column-header {
display: block;
text-align: center;
margin: 0 auto
}
.global-footer .email-signup .footer-email-acquisition {
margin: 10px auto 20px;
text-align: center
}
}
@media only screen and (max-width: 760.98px) {
.global-footer {
width: 100%;
margin: 0 auto
}
.global-footer .social-container {
display: block;
margin: 0 auto;
text-align: center
}
.global-footer .links {
width: 100%;
text-align: center;
margin: 40px 0 0
}
.global-footer .links ul li {
text-align: center;
line-height: 1.4em
}
.global-footer .links.company {
width: 50%;
float: left
}
.global-footer .links.information {
width: 50%;
float: right
}
.global-footer .email-signup {
display: block;
margin: 30px auto 0;
max-width: 300px
}
.global-footer .email-signup .column-header {
display: block;
text-align: center;
margin: 0 auto
}
.global-footer .email-signup .footer-email-acquisition {
margin: 15px auto;
text-align: center;
width: 100%
}
}
<ul class="nav-categories discover-active">
<li class="nav-category-and-subnav discover">
<div class="nav-category">
<span class="nav-category-padding">Discover</span> <i aria-hidden="true" class="fa fa-angle-down"><svg height="1792"
viewbox="0 0 1792 1792"
width="1792"
xmlns="http://www.w3.org/2000/svg">
<path d="M1395 736q0 13-10 23l-466 466q-10 10-23 10t-23-10L407 759q-10-10-10-23t10-23l50-50q10-10 23-10t23 10l393 393 393-393q10-10 23-10t23 10l50 50q10 10 10 23z"></path></svg></i>
<div class="subnav">
<a href="https://jump.refinery29.com/join/24/signup-ca-refresh"><img src="images/thisweek.jpg"></a>
<p class="close">X</p>
</div>
</div>
</li>
<li class="nav-category-and-subnav watch">
<div class="nav-category">
<span class="nav-category-padding">Watch</span> <i aria-hidden="true" class="fa fa-angle-down"><svg height="1792"
viewbox="0 0 1792 1792"
width="1792"
xmlns="http://www.w3.org/2000/svg">
<path d="M1395 736q0 13-10 23l-466 466q-10 10-23 10t-23-10L407 759q-10-10-10-23t10-23l50-50q10-10 23-10t23 10l393 393 393-393q10-10 23-10t23 10l50 50q10 10 10 23z"></path></svg></i>
<div class="subnav">
<div class="column">
Original Series
</div>
<div class="column">
Trending Videos
</div>
<p class="close">X</p>
</div>
</div>
</li>
</ul>
</nav>