.animate ScrollTop工作但不顺畅

时间:2017-05-08 19:16:12

标签: javascript jquery jquery-ui

我有Animate ScrollTop的JQuery代码

浏览器滚动到所需位置但不顺畅。

function scrollto_aboutUsSection(){
// alert("about us scroll called");
$("html,body").animate({scrollTop: $("#aboutUs_section").offset().top }, 0.001);
}

HTML代码如下

<div id="container">

        <?php include("Includes/header&nav.html"); ?>

        <div id="content">

            <?php include("Includes/information_section.html"); ?>

            <section id = "aboutUs_section" class="Section">
                <h2 class="textShadow big_h2_font"> About Us </h2>
                <p class="textShadow">  In 1987, Our founders laid the foundation of jewellery store in Gakhar Plaza, Saddar, Rawalpindi. Since that time we are in service in presentation of artistic jewels by the hands of talented craft persons and skilled artists. We still try our best to come up with ideas that matches with yours most, keeping the eye on craftmanships side by side. We deal in 21K, Embedded and non Embedded Jewels generally.
                </br></br>If you are looking for 22K, we take orders as well.
                </br></br>Visit our Gallery and have a look at our Jewels Range.  </p>
            </section> 
</div> </div>

其他函数调用此JQuery函数。

我在body标签内的html代码中包含了<?php ?>。此 JQuery函数也会调用页面加载。所以不是它顺利跳过动画的原因。

PHP 之前,它运行正常。

1 个答案:

答案 0 :(得分:1)

你的速度非常慢。使用此:

$("html,body").animate({scrollTop: $("#aboutUs_section").offset().top }, 1000);

请注意最后一个值1000,而不是旧的0.001

速度以毫秒为单位。所以1000是1秒。

相关问题