1

我这里有个问题。我试图对角滚动我的文档。它获取文档的宽度和高度,并将其值添加到每个部分元素中。我知道如何在 y 角度滚动它,但是可以找到一种方法使 x 角度滚动同步滚动宽度为 y 角度。

感谢您的提示!

这是我的js:

$(function() {
    var windowHeight = $(window).height();
    var windowWidth = $(window).width();
    var sectionsNumbers = $("#content section").length - 1;
    var sectionCount = 0;
    // Scroll sets
    var windowScrollX = ((sectionsNumbers + 1) * windowWidth) - windowWidth;
    alert(windowScrollX);
    // Set mask w and h
    $("#mask").css("width", windowWidth);
    $("#mask").css("height", windowHeight);
    $(".scrollRule").css("height", (sectionsNumbers + 1) * windowHeight);
    $("#content section").each(function() {
        // Defines its width and height
        $(this).css("width", windowWidth);
        $(this).css("height", windowHeight);
        // Defines its position
        $(this).css("left", sectionCount * windowWidth);
        $(this).css("top", sectionCount * windowHeight);
        sectionCount++;
    });
    // When window scrolls
    $(window).scroll(function() {
        var curScrollTop = $(window).scrollTop();
        $("#debug").html(curScrollTop);
        $("#content").css("top", "-" + curScrollTop);
    });
});​

我知道了!

我只需要将窗口总宽度除以窗口总滚动高度。谢谢大家!

4

1 回答 1

2

尝试使用 jQuery 的动画功能。只需将我的代码示例中的整数替换为您计算出的位置值即可。

jQuery('html,body').animate(
    {
         scrollTop: 25
         ,scrollLeft: 20
    }
    ,'slow'
);

来源:http ://api.jquery.com/animate/

于 2012-05-25T15:21:08.437 回答