gpt4 book ai didi

jQuery 哈希更改未在移动设备上触发

转载 作者:行者123 更新时间:2023-11-28 05:00:49 25 4
gpt4 key购买 nike

我有一个菜单,它使用 anchor 标记根据选择的 anchor 标记提供不同的内容。当菜单项被触发时,通过将链接上的散列与浏览器 url 中的散列相匹配,将事件类添加到父级。

一切都在桌面上完美运行,但一旦我转到移动设备上,它就不会启动。

代码如下:

$(window).on('hashchange', function(e) {
if ($('.menu-item').hasClass('active')) {
$(".menu-item").removeClass("active");
$('[href$="' + window.location.hash + '"]').parent(this).addClass("active");
}
});
#artistNavigation {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
text-align: left;
width: 100%;
height: auto;
margin: 0 auto;
position: relative;
font-family: "Oswald", sans-serif;
box-shadow: 0 1px 0 0 #ddd;
-webkit-box-shadow: 0 1px 0 0 #ddd;
}
@media (max-width: 1000px) {
#artistNavigation {
padding-top: 50px;
width: calc(100% - 60px);
position: relative;
}
#artistNavigation.open li.menu-item {
display: block;
}
}
#artistNavigation li {
display: inline-block;
*display: inline;
zoom: 1;
text-align: left;
vertical-align: middle;
padding-right: 45px;
position: relative;
/*active state*/
}
@media (max-width: 1000px) {
#artistNavigation li {
display: block;
text-align: center;
}
#artistNavigation li.mobi {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 30px;
z-index: 99;
}
#artistNavigation li.menu-item {
display: none;
list-style-type: none;
}
#artistNavigation li.active {
display: block !important;
position: absolute;
top: 0;
left: 0;
right: 70px;
height: 30px;
z-index: 89;
display: block;
background: #fff;
}
#artistNavigation li.active a {
-webkit-transform: translateX(35px);
transform: translateX(35px);
}
}
#artistNavigation li a {
-webkit-transition: color 200ms ease;
-moz-transition: color 200ms ease;
-o-transition: color 200ms ease;
-ms-transition: color 200ms ease;
transition: color 200ms ease;
display: inline-block;
*display: inline;
zoom: 1;
padding: 17px 0;
text-align: center;
font-size: 12px;
line-height: 15px;
text-transform: uppercase;
white-space: nowrap;
cursor: pointer;
color: #b2b2b2;
position: relative;
border-bottom: solid 2px transparent;
}
@media (max-width: 1000px) {
#artistNavigation li a {
padding: 1rem 0;
}
}
#artistNavigation li a,
#artistNavigation li a:visited,
#artistNavigation li a:active,
#artistNavigation li a:link {
color: #b2b2b2;
}
#artistNavigation li:hover > a,
#artistNavigation li:focus > a,
#artistNavigation li.active a {
color: #000;
border-bottom: solid 2px #25cbd3;
}
#artistNavigation li.pdf {
position: absolute;
right: 0;
top: 12px;
padding-right: 0;
text-transform: uppercase;
font-size: 12px;
color: #25cbd3;
padding-bottom: 16px;
border-bottom: solid 2px transparent;
}
#artistNavigation li.pdf:hover {
cursor: pointer;
color: #454545;
}
@media (max-width: 1000px) {
#artistNavigation:hover,
#artistNavigation:focus {
height: auto;
}
#artistNavigation li:active {
position: absolute;
top: 0;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav id="art-nav" role="navigation">
<div class="artist-nav-box">
<ul id="artistNavigation">
<li class="menu-item active"><a href="#Commercial">Commercial</a>
</li>
<li class="menu-item"><a href="#Fashion">Fashion</a>
</li>
<li class="menu-item"><a href="#Lifestyle">Lifestyle</a>
</li>
<li class="menu-item"><a href="#Portaits">Portaits</a>
</li>
<li class="menu-item"><a href="#Places">Places</a>
</li>
<li class="menu-item"><a href="#Animals">Animals</a>
</li>
<li class="menu-item"><a href="#Great-White-Shark">Great White Shark</a>
</li>
<li class="menu-item"><a href="#Panoramics">Panoramics</a>
</li>
<li class="menu-item"><a href="#Masai">Masai</a>
</li>
</ul>
</div>

</nav>

我确定这是我遗漏的简单内容,请原谅 sass 生成的 CSS。

最佳答案

事实证明这是一个 CSS 问题 - 我删除了 :active 状态的所有实例并将其替换为我的 .active 类。 :active 状态将通过 css 将元素从相对于绝对位置的位置移动 - 因此当点击向下时,菜单项将移动。完全停止 2 个半小时 :/

关于jQuery 哈希更改未在移动设备上触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40125941/

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