【发布时间】:2018-01-24 04:55:30
【问题描述】:
哈。我的小项目遇到了麻烦。我创建了<a href="slogannya">some icon</a> 和<blockquote id="slogannya">,但是当我点击<a> 标签时它不起作用。这是我的代码:
HTML
<section class="to-content">
<a class="scrollTo" href="#slogannya">
<button type="button">
<i class="material-icons">keyboard_arrow_down</i>
</button>
</a>
</section>
<section class="slogan">
<blockquote id="slogannya">
<p>Wanna create an event? <br> or you want to give some advice to us? Use the form below </p>
</blockquote>
</section>
jQuery
$(document).ready(function () {
$(".scrollTo").on('click', function (e) {
e.preventDefault();
var target = $(this).attr('href');
$('html, body').animate({
scrollTop: ($(target).offset().top)
}, 2000);
});
});
我怎样才能完成这项工作?请帮帮我:)
编辑
我知道我的问题是什么。在我的项目中,我有一个名为“general.css”的 css(此 css 内容 css 重置和任何页面的其他样式)。在这个 css 中,它使任何元素成为 box-sizing: border-box; 和其他样式。不知道具体是什么问题。但是当我删除我的“general.css”时,平滑滚动就可以了。谢谢你所有的回答朋友:),我很感激!!
【问题讨论】:
-
您完全可以在没有 jQuery 的情况下使用它。只需在页面的某个位置定义 然后链接到它这样,更改“thispage.html”到您的页面名称。
标签: html anchor anchor-scroll