javascript - 对 Angular 滚动 Javascript

标签 javascript jquery

我在这里遇到了一个问题。我正在尝试沿对 Angular 线滚动我的文档。它采用文档宽度和高度,并将其值添加到每个部分元素中。我知道如何在 y Angular 滚动它,但可以找到一种方法使 x Angular 滚动同步滚动 y Angular 宽度。

感谢任何提示!

这是我的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);
    });
});​

我明白了!

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

最佳答案

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

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

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

关于javascript - 对 Angular 滚动 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10756988/

相关文章:

javascript - 输入更改时的多个缩略图库

javascript - 重新加载后重新连接弹出窗口

php - Javascript 爆炸和循环

javascript - 没有大括号的 JavaScript 中的 Lambda 函数语法

javascript - FeathersJS - 如何取消错误 Hook

javascript - 将对象拖到父对象之外

jquery - 在响应式设计中填满页面宽度的导航

javascript - 如何找到内里的类(class)并更改上一级?

javascript - jQuery,将我的 jquery 代码移动到外部文件时出现引用错误

javascript - 如何将 jQuery Validate 错误消息放在标签后面?