[英]jQuery scroll to div onclick not working
我正在嘗試在我的網站http://www.dicosoftware.com上實現div滾動,以平滑滾動到該網站的每個部分,但是它不起作用。 您可以訪問該網站進行驗證,我們將非常感謝您提供的任何反饋意見。
我在main.js文件下使用以下jQuery函數。
$(".js--scroll-to-main").click(function(){
$('html,body').animate({scrollTop:$("#header").offset().top},2000);
});
$(".js--scroll-to-about_us").click(function({
$('html,body').animate({scrollTop:$("#sectionabout_us").offset().top},2000;
});
$(".js--scroll-to-services").click(function(){
$('html, body').animate({scrollTop:$("#section-services").offset().top},2000);
});
$(".js--scroll-to-contact_us").click(function(){
$('html, body').animate({scrollTop:$("#section-contact_us").offset().top},2000);
});
我的鏈接設置在無序列表下
<ul class="main-nav hidden js--main-nav">
<li> <a class="js--scroll-to-main" href="#">Inicio</a> </li>
<li> <a class="js--scroll-to-about_us" href="#">Nosotros</a> </li>
<li> <a class="js--scroll-to-services" href="#">Servicios</a> </li>
<li class="contact-link"> <a class="js--scroll-to-contact_us" href="#">Contactanos</a> </li>
</ul>
並且每個部分都在以下div下設置。
<header id="header"> ... </header>
<section class="section-about_us js--section-about_us" id="section-about_us"> ... </section>
<section class="section-services js--section-services" id="section-services"> ... </section>
<section class="section-contact js--section-contact" id="section-contact_us"> ... </section>
注意控制台中的錯誤:
TypeError: $('html, body').animate is not a function.
在一個類似的問題中 ,有人指出,jQuery的苗條構建不包含很多功能。
您應該將下面的腳本更改為完整版本的jQuery:
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js"></script>
如:
https://code.jquery.com/jquery-3.1.1.min.js
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.