Home >Web Front-end >JS Tutorial >jquery scrollTop method shows and hides the top navigation bar according to the scroll pixel_jquery

jquery scrollTop method shows and hides the top navigation bar according to the scroll pixel_jquery

WBOY
WBOYOriginal
2016-05-16 17:33:101984browse

This article uses jquery's scrollTop method to monitor the vertical scrolling pixels of the page, and hide or display the top navigation bar based on the pixels.
Effect preview URL: http://www.keleyi.com/keleyi/phtml/scrolloversee.htm

Introduction to scrollTop:

Syntax
$(selector).scrollTop(offset)

Parameters
offset
Description
Optional. Specifies the offset, in pixels, from the top of the scroll bar.

Definition and Usage
scrollTop() method returns or sets the vertical position of the scroll bar of the matching element.
scroll top offset refers to the offset of the scroll bar relative to its top.
If this method sets no parameters, returns the offset in pixels from the top of the scroll bar.

Tips and Notes
Note: This method works for both visible and invisible elements.
Note: When used to get a value, this method only returns the scroll top offset of the first matching element.
Note: When used to set a value, this method sets the scroll top offset of all matching elements.

Attach the complete code, save it to an html file, open it to experience the effect:

Copy the code The code is as follows:




监视滚动像素,显示或隐藏顶部导航条-柯乐义





请滚动鼠标使页面向下

www.keleyi.com

欢迎

hi

柯乐义

keleyi.com

keleyi

keleyi.com

柯乐义

柯乐义 监视下滚像素

A

jquery


keleyi.com

完整代码




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