Js operation scroll bar event instance_javascript skills

Source: Internet
Author: User
This article mainly introduces how to operate the scroll bar event in js. The example analyzes the usage skills of the scroll bar and related precautions, for more information about how to operate a scroll bar event in js, see the example in this article. Share it with you for your reference. The specific analysis is as follows:

I have been wondering how to monitor the events of the scroll bar. Now I understand it.

The code below is to listen to the scroll bar as long as it moves, the lower returns the top p display and hidden code

window.onscroll = function () {   var t = document.documentElement.scrollTop || document.body.scrollTop;  if (t > 0) {     $(".cbbfixed").css("bottom", "10px");   } else {     $(".cbbfixed").css("bottom", "-85px");   } }

Note:

T: The distance from the scroll bar to the top end

T> 0, that is, once the scroll bar is rolled, the if () Statement is executed immediately. The code in else () is that when the scroll bar reaches the top, the p at the top is returned to hide

Return to the top button click operation:

$("#cgotop").click(function(){   $('body,html').animate({ scrollTop: 0 }, 100);   return false; });

Supplement:

1. Listen to the scroll bar event of an element

$(selector).scroll(function(){.......});


2. Get the scroll distance of the scroll bar

$(selector).scrollTop();$(selector).scrollLefft();

I hope this article will help you design javascript programs.

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.