search
HomeWeb Front-endJS TutorialUsage examples of scrollIntoView
Usage examples of scrollIntoViewJun 29, 2017 pm 02:49 PM
iescrollwindow

Scrolling of DOM

The DOM specification does not stipulate what kind of scrolling page area each browser needs to implement. Each browser implements corresponding methods and can use different methods to control the scrolling of the page area. These methods exist as extensions of the HTMLElement type, so they can be used on all elements.

1. scrollIntoView(alignWithTop) Scrolls the browser window or container element so that the current element can be seen within the visible range of the current window. If alignWithTop is true, or if it is omitted, the window will scroll as much as possible until the top of itself is flush with the top of the element. ------- Currently, all browsers support

2. scrollIntoViewIfNeeded(alignCenter) only scrolls the browser window or container element when the current element is not visible within the visible range of the window. Finally make the current element visible. If the current element is visible in the viewport, this method does nothing. If the optional parameter alignCenter is set to true, it means that the element will be displayed in the middle of the window (vertical direction) ------Safari and Chrome implement this method

3, scrollByLines(lineCount) The content is scrolled by the specified number of lines. The value of lineCount can be positive or negative. ---Safari and Chrome implement this method

4. scrollByPages(pageCount) scrolls the content of the element to the specified page height. The specific height is determined by the height of the element. ---Safari and Chrome implement this method

scrollIntoView() and scrollIntoVIewIfNeeded() affect the element's window, while scrollByLines() and scrollByPages() affect the element itself. The following is A few examples:

//将页面主体滚动5行
document.body.scrollByLines(5);

/确保当前元素可见
document.getElementById(“test”).scrollIntoView();   //
//true:对象的顶端与当前窗口的顶部对齐
//false:对象的底端与当前窗口的顶部对齐

//确保只在当前元素不可见的情况下才使其可见
document.getElementById(“test”).scrollIntoViewIfNeeded();
//将页面主体往回滚1页
doument.body.scrollByPages(-1);
由于只有scrollIntoView被各浏览器均支持,所以这个方法最为常用


The above is the detailed content of Usage examples of scrollIntoView. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
win7窗口全屏快捷键是什么win7窗口全屏快捷键是什么Jun 29, 2023 pm 07:33 PM

win7窗口全屏快捷键是什么?我们在使用win7系统的时候,有时候开启软件的时候,它的运行窗口不是全屏的,这个时候我们需要通过鼠标去最大化窗口。那么有什么快捷键可以快速去切换最大化窗口显示呢?接下来和大家分享win7窗口全屏快捷键教程。一、Alt+Enter一般程序,包括大部分游戏在内的没有自带全屏快捷键的程序。二、F11几乎所有的浏览器,都可以用这个快捷键进行全屏。三、Alt+V+U包括word文档在内的大部分文档工具都可以用这个快捷键进行全屏。四、Ctrl+F/Space很多播放器软件,让视

谷歌浏览器怎么设置每次打开都是新的窗口谷歌浏览器怎么设置每次打开都是新的窗口Mar 06, 2024 pm 06:19 PM

谷歌浏览器怎么设置每次打开都是新的窗口?狠毒用户喜欢使用谷歌浏览器办公或者学习,这款浏览器具有安全、快速、便捷的特点,不同的用户使用浏览器的喜好不同,一些用户喜欢打开谷歌浏览器就是新的标窗口,方便快速搜索,那么如何设置呢。接下来小编就给大家带来谷歌浏览器每次打开都是新的窗口设置教程,感兴趣的朋友快来学习一下吧。谷歌浏览器每次打开都是新的窗口设置教程1、将电脑桌面上的谷歌浏览器双击打开之后,点击右上角的【三个点】的图标位置进行单击。2、找到【设置】这个选项进入到页面中(如图所示)。3、进入到谷歌浏

Win7任务栏显示在桌面右侧窗口怎么办Win7任务栏显示在桌面右侧窗口怎么办Jun 29, 2023 pm 07:41 PM

  Win7任务栏显示在桌面右侧窗口怎么办?一般情况下任务栏默认是在屏幕底部的,但近期有Win7用户打开电脑发现任务栏跑到屏幕的右侧窗口去了,那么有没有什么方法可以将其修改回来呢?很多小伙伴不知道怎么详细操作,小编下面整理了Win7任务栏显示在桌面右侧窗口解决步骤,如果你感兴趣的话,跟着小编一起往下看看吧!Win7任务栏显示在桌面右侧窗口解决步骤  1、首先我们右键点击桌面右侧窗口的任务栏,选择属性,如下图所示:  2、打开的任务栏和属性窗口中,在屏幕上的任务栏位置选择底部,并勾选锁定任务栏,点

Internet Explorer 打开 Edge:如何停止 MS Edge 重定向Internet Explorer 打开 Edge:如何停止 MS Edge 重定向Apr 14, 2023 pm 06:13 PM

长期以来,InternetExplorer的失宠一直不是秘密,但随着Windows11的到来,现实开始了。Edge将来不再有时取代IE,它现在是微软最新操作系统中的默认浏览器。目前,您仍然可以在Windows11中启用InternetExplorer。但是,IE11(最新版本)已经有了一个正式的退役日期,即2022年6月15日,时间在流逝。考虑到这一点,您可能已经注意到InternetExplorer有时会打开Edge,而您可能不喜欢它。那么为什么会这样呢?在

win11无法使用ie11浏览器怎么办?(win11用不了ie浏览器)win11无法使用ie11浏览器怎么办?(win11用不了ie浏览器)Feb 10, 2024 am 10:30 AM

越来越多的用户开始升级win11系统,由于每个用户的使用习惯不同,还是有不少用户在使用ie11浏览器,那么win11系统用不了ie浏览器,该怎么办呢?windows11还支持ie11吗?下面就来看看解决办法。win11无法使用ie11浏览器的解决方法1、首先右键开始菜单,选择“命令提示符(管理员)”打开。2、打开之后,直接输入“Netshwinsockreset”,回车确定。3、确定之后再输入“netshadvfirewallreset&rdqu

关闭电脑游戏广告弹出窗口的方法关闭电脑游戏广告弹出窗口的方法Jul 07, 2023 pm 08:57 PM

很多网友在玩win10电脑时,相信都会遇到一些广告弹窗的骚扰,有时在玩游戏时可能会出现游戏广告弹窗导致体验不佳。那么win10电脑右下角闪烁游戏广告怎么办?如何关闭电脑游戏广告弹窗?以下小编就教你如何关闭电脑的游戏广告弹窗。关闭电脑游戏广告弹出窗口的方法。第一步:找到闪烁的弹出窗口进程名称一、闪烁弹窗出现时,先不要关闭,右键打开电脑底部的任务栏设置。2.在任务栏下找到通知区域,点击在任务栏上显示选择哪些图标。3.这里列出的图标曾经出现在你的任务栏上,所以即使你关闭了弹出窗口,这里还是有记录的。你

windows10窗口颜色设定教程windows10窗口颜色设定教程Jul 08, 2023 pm 11:25 PM

许多windows10客户感觉自己电脑默认的窗口颜色不好看,要想设成其他颜色,应当怎么设置呢?大家需要先进入设置面板,找到个性化进到,随后点击颜色,之后就会出现一个颜色面板,你可以在其中挑选想要的颜色,以后保存设置,这时候颜色就改好了。你随便开启一个窗口就能看到颜色早已改变了。windows10窗口颜色怎么设置:1、改窗口边框的颜色十分简单,首先进到系统配置。2、随后点击“个性化”,如图所示。3、在弹出的窗口中,挑选左边栏的“颜色”按键。4、然后在右侧的颜色列表中挑选需要的颜色即可,随后点击确定

Win10打开IE自动跳转到Edge怎么取消_IE浏览器页面自动跳转的解决办法Win10打开IE自动跳转到Edge怎么取消_IE浏览器页面自动跳转的解决办法Mar 20, 2024 pm 09:21 PM

近期不少的win10用户们在使用电脑浏览器的时候发现自己的ie浏览器总是自动的跳转到edge浏览器,那么win10打开ie自动跳转edge怎么关闭?。下面就让本站来为用户们来仔细的介绍一下win10打开ie自动跳转edge关闭方法吧。1、我们登录edge浏览器,点击右上角...,找下拉的设置选项。2、我们进入设置后,在左侧栏点击默认浏览器。3、最后我们在兼容性中,勾选不允许IE模式下重新加载网站,重启ie浏览器即可。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools