Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 使用ScrollMagic和视差设计平滑滚动_Jquery_Html_Web_Parallax_Scrollmagic - Fatal编程技术网

Jquery 使用ScrollMagic和视差设计平滑滚动

Jquery 使用ScrollMagic和视差设计平滑滚动,jquery,html,web,parallax,scrollmagic,Jquery,Html,Web,Parallax,Scrollmagic,我在我的网站上结合了视差滚动和ScrollMagic,但是遇到了锚链接滚动的问题:链接可以滚动到页面上的位置;滚动不是平滑的,只是跳跃 以下是相关代码: <script> $(function() { var controller = new ScrollMagic.Controller(); var tween = TweenMax.from("#animate", 0.5, {autoAlpha: 0, scale: 0.7});

我在我的网站上结合了视差滚动和ScrollMagic,但是遇到了锚链接滚动的问题:链接可以滚动到页面上的位置;滚动不是平滑的,只是跳跃

以下是相关代码:

<script>
    $(function() {
        var controller = new ScrollMagic.Controller();

        var tween = TweenMax.from("#animate", 0.5, {autoAlpha: 0, scale: 0.7});

        var scene = new ScrollMagic.Scene({triggerElement: "a#home", duration: 200, triggerHook: "onLeave"})
            .setTween(tween)
            .addIndicators() // add indicators (requires plugin)
            .addTo(controller);

        // change behaviour of controller to animate scroll instead of jump
        controller.scrollTo(function (newpos) {
            TweenMax.to(window, 0.5, {scrollTo: {y: newpos}});
        });

        //  bind scroll to anchor links
        $(document).on("click", "a[href^='#']", function (e) {
            var id = $(this).attr("href");
            if ($(id).length > 0) {
                e.preventDefault();

                // trigger scroll
                controller.scrollTo(id);

                // if supported by the browser we can even update the URL.
                if (window.history && window.history.pushState) {
                    history.pushState("", document.title, id);
                }
            }
        });


    });
</script>

$(函数(){
var controller=new ScrollMagic.controller();
var tween=TweenMax.from(“#animate”,0.5,{autoAlpha:0,scale:0.7});
var scene=new ScrollMagic.scene({triggerement:“a#home”,持续时间:200,triggerHook:“onLeave”})
.塞特温(吐温)
.addIndicators()//添加指示器(需要插件)
.addTo(控制员);
//将控制器的行为更改为动画滚动而不是跳跃
控制器。滚动到(功能(newpos){
TweenMax.to(窗口,0.5,{scrollTo:{y:newpos}});
});
//绑定滚动到锚链接
$(文档)。在(“单击”、“a[href^='#']”上,函数(e){
var id=$(this.attr(“href”);
如果($(id).length>0){
e、 预防默认值();
//触发卷轴
控制器。滚动到(id);
//如果浏览器支持,我们甚至可以更新URL。
if(window.history&&window.history.pushState){
history.pushState(“,document.title,id);
}
}
});
});

如何才能成功实现平滑滚动?

如果您能提供小提琴或其他东西,可能会有所帮助。如果您能提供小提琴或其他东西,可能会有所帮助。