JS achieves scrolling display/hiding of fixed position elements in the window, js window

Source: Internet
Author: User

JS achieves scrolling display/hiding of fixed position elements in the window, js window

An element is displayed at a fixed position in the window. When the page height is greater than a certain height and the page is scrolled down, the element is displayed. When the page position is smaller than a certain height or the page is scrolled up, the element is hidden.

First, we will show you:

1. html

<P id = "selected-case-count"> <span class = 'form-control'> selected: <span class = "casecount"> 0 </span> </p>

2. css

P # selected-case-count {position: fixed;/* fixed element position */top: 2px;/* example from top */right: 40px; /* from the right side */color: red ;}

3. js

$(function() {$("#selected-case-count").hide();});var preTop=0;var currTop=0;$(function () {$(window).scroll(function(){currTop=$(window).scrollTop();if(currTop<preTop){$("#selected-case-count").fadeOut(200);}elseif ($(window).scrollTop()>600){$("#selected-case-count").fadeIn(500);}else{$("#selected-case-count").fadeOut(500);}preTop=$(window).scrollTop();});});

The above is a small part of the JS Implementation of rolling display/hiding the fixed position elements of the window with the page. I hope it will be of great help!

Articles you may be interested in:
  • Js textarea automatically increases and hides the scroll bar
  • How to locate a fixed layer in js
  • Example of a fixed-position floating window implemented by javascript
  • How to display js control elements at fixed positions on the screen and monitor screen height changes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.