javascript - 我正在编写一个页面,该页面在单击链接时向下滚动。点击后显示为蓝色

标签 javascript html css

所以我正在编写一个网站,该网站的主页有一个跨度,允许您单击它,然后向下滚动到一个新部分,滚动有效,然后向下滚动,但如果我手动向上滚动,文本显示为蓝色并加下划线。有什么办法可以阻止这种情况发生。

    <a class="Scroll" href="#section02"><span></span>Scroll</a>

这是我使用的 HTML,新部分的 ID 为 section02。

$(function() {
$('a[href*=#]').on('click', function(e) {
    e.preventDefault();
    $('html, body').animate({ scrollTop: 
$($(this).attr('href')).offset().top}, 500, 'linear');
    });
});

这是用到的JS。

.Scroll {
position: absolute;
height: 20px;
z-index: 20;
display: inline-block;
color: #fff;
font : normal 400 20px/1 'Josefin Sans', sans-serif;
letter-spacing: .1em;
text-decoration: none;
transition: opacity .3s;
}

.Scroll::after{
position: absolute;
height: 20px;
z-index: 20;
display: inline-block;
color: #fff;
font : normal 400 20px/1 'Josefin Sans', sans-serif;
letter-spacing: .1em;
text-decoration: none;
transition: opacity .3s;
}

.Scroll:hover {
    opacity: .5;
    color: #fff;
    text-decoration: none;
}

这是我使用的 CSS,我认为它可能是因为我在单击链接后没有样式,但问题仍然存在,尽管悬停样式在滚动条为蓝色时仍然有效。

What the scroll link looks like before.

And what it looks like after being pressed and manually scrolling up.

感谢任何帮助

最佳答案

试试这个:

.Scroll a, a:hover, a:visited, a:link, a:active {
    color: #FFFFFF;
    text-decoration: none;
}

text-decoration: none; 应该可以解决问题并删除下划线。如果它仍然不起作用,请在 text-decoration 之后添加 !important,如下所示:text-decoration: none !important;

关于javascript - 我正在编写一个页面,该页面在单击链接时向下滚动。点击后显示为蓝色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43644273/

相关文章:

html - 我可以使用元标记来确保我的网站按比例缩小以适应 iPad 视口(viewport)吗?

javascript - Div 旋转在 JSFiddle 中有效,但在实际元素中无效

html - CSS 未显示在页面的特定部分

javascript - 轮询时 promise 异步等待

javascript - html5 视频在 ipad 上不工作

html - LESScss if 条件变量不为空

css - z-index 不适用于固定定位

css border-box 属性不适用于大填充值

javascript - Jquery 条件不起作用

javascript - 用于在 GitHub 中通过按 Ctrl+Enter(内置热键)提交问题或发布评论时创建确认弹出窗口的用户脚本