如何滚动到我的按钮? .scrollTo()不起作用

时间:2014-04-14 18:40:42

标签: javascript jquery html

There is my page

只是一个简单的照片浏览器。

但我不知道如何通过我的按钮向下/向上滚动。

我尝试使用jquery .scrollTo(y-offset),但它不起作用。

这是我的功能:

function ScrollDown() {
        var $chapters = $('#dContent').children('.sContent');
        var $chScrollPositions = new Array();

        $chapters.each(function (i) {
            $chScrollPositions[i] = Math.round($(this).offset().top - $('#dContent').offset().top) - 10;
            //alert($chScrollPositions[i]);
        });

        var last = $chapters.parent().find('.active').removeClass('active').index();

        var next = (last + 1 == $chapters.length) ? 0 : last + 1; // Loop around to first chapter
        $chapters.eq(next).addClass('active'); // Set Next Chapter Active
        $('#dContnet').scrollTo($chScrollPositions[next]);
    }

你能帮帮我吗?

感谢。

1 个答案:

答案 0 :(得分:0)

使用animate执行此操作

$("html:not(:animated),body:not(:animated)").animate({ scrollTop: 1000}, 300);