zoukankan      html  css  js  c++  java
  • Element.scrollIntoView()

    Element.scrollIntoView() 方法让当前的元素滚动到浏览器窗口的可视区域内。

    语法
    element.scrollIntoView(); // 等同于element.scrollIntoView(true) element.scrollIntoView(alignToTop); // Boolean型参数 element.scrollIntoView(scrollIntoViewOptions); // Object型参数

    参数
    alignToTop (Boolean型参数)

    1.如果为true,元素的顶端将和其所在滚动区的可视区域的顶端对齐。
    2.如果为false,元素的底端将和其所在滚动区的可视区域的底端对齐。

    scrollIntoViewOptions (Object型参数)
    {
        behavior: "auto"  | "instant" | "smooth",
        block:    "start" | "end",
    }
    1.
    behavior 定义动画过渡效果(决定页面是如何滚动),默认为 "auto"auto与instant都是瞬间跳到相应的位置,而smooth就是有动画的过程

    2.如果是一个boolean,true 相当于{block: "start"},false 相当于{block: "end"}

    示例
    var element = document.getElementById("box");
    
    element.scrollIntoView();
    element.scrollIntoView(false);
    element.scrollIntoView({block: "end"});
    element.scrollIntoView({block: "end", behavior: "smooth"});

    注意
    取决于其它元素的布局情况,此元素可能不会完全滚动到顶端或底端。
     




  • 相关阅读:
    博客园的Windows Mobile开发专栏
    使大脑迟钝的9种不良习惯
    javascript中实现QueryString的function
    DeviceIoControl实现异步的方法总结
    List of Scientist`s Names
    制版经验谈
    AVRUSB技术探讨(转)
    unexpected WaitForXfer() behavior
    openMP讨论帖
    全角半角SBCDBC
  • 原文地址:https://www.cnblogs.com/cyfeng/p/11910076.html
Copyright © 2011-2022 走看看