[英]In-page anchor not working in Firefox
I'm having issues with my in-page anchor tag. 我的页内定位标记存在问题。 When you click the down arrow,
<a href="#two">
, it should scroll down to the <div id="two">
. 单击向下箭头
<a href="#two">
,它应向下滚动到<div id="two">
。 It's working just fine in Chrome & Safari, but Firefox doesn't register the arrow as a link at all. 在Chrome和Safari中它可以正常工作,但是Firefox根本没有将箭头注册为链接。
I've tried changing the <div>
to an <a>
tag, replacing <div id="two">
with <a name="two">
, I can't seem to get anything to work for me in Firefox. 我尝试将
<div>
更改为<a>
标记,将<div id="two">
替换为<a name="two">
,但在Firefox中似乎无法正常工作。
Thoughts? 有什么想法吗?
$(function() { $('a[href*="#"]:not([href="#"])').click(function() { if (location.pathname.replace(/^\\//, '') == this.pathname.replace(/^\\//, '') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); if (target.length) { $('html, body').animate({ scrollTop: target.offset().top }, 1000); return false; } } }); });
@import url(http://weloveiconfonts.com/api/?family=fontawesome); [class*="fontawesome-"]:before { font-family: 'FontAwesome', sans-serif; } * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; -ms-box-sizing: border-box; box-sizing: border-box; } * { font-family: 'Helvetica Neue', serif; font-weight: lighter; letter-spacing: 1px; } .arrow { color: black; font-size: 5em; -o-transition:.5s; -ms-transition:.5s; -moz-transition:.5s; -webkit-transition:.5s; transition:.5s; } .arrow:hover { color: lightgray; } .button { background-color: transparent; border-color: transparent; margin-left: 50%; margin-right: 50%; margin-bottom: 250px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script> <div> <button class="button"> <a href="#two"> <span class="fontawesome-angle-down arrow"></span> </a> </button> </div> <div id="two" class="section"> <article class="fade relative"> <div id="name"> <a href="#"> <a href="https://iamtrask.github.io/" target="_blank"> <img src="http://placehold.it/350x150" alt="I Am Trask" /> </a> </a> <h2 class="absolute-text art-title">I AM TRASK</h2> <div id="hidden" class="absolute-text"> <p>• bullet 1<br>• bullet 2</p> </div> </div> </article> </div>
Just remove that <button>
tag, it makes no sense in this context, since you don't want a button, but an icon. 只需删除该
<button>
标记,在这种情况下就没有意义,因为您不需要按钮,而是图标。 in the following snippet I assigned your .button
class to the parent div and removed the button element itself. 在以下代码段中,我将
.button
类分配给了父div,并删除了button元素本身。
I also added this to get rid of the underline below the arrow link: 我还添加了它,以消除箭头链接下方的下划线:
.button a {
text-decoration: none;
}
$(function() { $('a[href*="#"]:not([href="#"])').click(function() { if (location.pathname.replace(/^\\//, '') == this.pathname.replace(/^\\//, '') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); if (target.length) { $('html, body').animate({ scrollTop: target.offset().top }, 1000); return false; } } }); });
@import url(http://weloveiconfonts.com/api/?family=fontawesome); [class*="fontawesome-"]:before { font-family: 'FontAwesome', sans-serif; } * { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; -ms-box-sizing: border-box; box-sizing: border-box; } * { font-family: 'Helvetica Neue', serif; font-weight: lighter; letter-spacing: 1px; } .arrow { color: black; font-size: 5em; -o-transition:.5s; -ms-transition:.5s; -moz-transition:.5s; -webkit-transition:.5s; transition:.5s; } .arrow:hover { color: lightgray; } .button { background-color: transparent; border-color: transparent; margin-left: 50%; margin-right: 50%; margin-bottom: 250px; } .button a { text-decoration: none; } #two { height: 800px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script> <div class="button"> <a href="#two"> <span class="fontawesome-angle-down arrow"></span> </a> </div> <div id="two" class="section"> <article class="fade relative"> <div id="name"> <a href="#"> <a href="https://iamtrask.github.io/" target="_blank"> <img src="http://placehold.it/350x150" alt="I Am Trask" /> </a> </a> <h2 class="absolute-text art-title">I AM TRASK</h2> <div id="hidden" class="absolute-text"> <p>• bullet 1<br>• bullet 2</p> </div> </div> </article> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.