Extended jquery Scroll event, support scroll start and scroll stop

Source: Internet
Author: User

Reference Address:

http://www.ghugo.com/special-scroll-events-for-jquery/

One of the events in JavaScript is a scrolling event, which triggers an event as long as you drag the scroll bar.

With jquery, this event scroll can view jquery api:http://api.jquery.com/scroll/

However, there is a flaw in the scroll event, which is that only the scroll bar can be judged, not the event when the scrollbar stops scrolling.

Now use jquery to expand the scroll event, adding

Not much to say, directly on the code is really point.

(function(){     varSpecial =jQuery.event.special, Uid1= ' D ' + (+NewDate ()), Uid2= ' D ' + (+NewDate () + 1); Special.scrollstart={setup:function() {             varTimer, Handler=function(evt) {var_self = This, _args=arguments; if(timer) {cleartimeout (timer); } Else{Evt.type= ' Scrollstart ';                    JQuery.event.handle.apply (_self, _args); } Timer= SetTimeout (function() {Timer=NULL;                 }, Special.scrollstop.latency);             }; JQuery ( This). Bind (' scroll ', handler). Data (uid1, handler); }, Teardown:function() {JQuery ( This). Unbind (' scroll ', jQuery ( This). Data (UID1));     }    }; Special.scrollstop={latency:300, Setup:function() {             varTimer, Handler=function(evt) {var_self = This, _args=arguments; if(timer) {cleartimeout (timer); } Timer= SetTimeout (function() {Timer=NULL; Evt.type= ' Scrollstop ';                     JQuery.event.handle.apply (_self, _args);                 }, Special.scrollstop.latency);             }; JQuery ( This). Bind (' scroll ', handler). Data (Uid2, handler); }, Teardown:function() {JQuery ( This). Unbind (' scroll ', jQuery ( This). Data (UID2)); }    }; })();

You can save the above code to a file, which is equivalent to a plugin, hehe. The calling method is as follows:

(function() {    jQuery (window). bind (function() {        console.log ("Start") );    });     JQuery (window). bind (function(e) {        console.log ("End");    }) ();

Extended jquery Scroll event, support scroll start and scroll stop

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.