Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to detect when scrolling occurs in JavaScript?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 03-02-2010
Member
 
Join Date: Aug 2006
Posts: 114
How to detect when scrolling occurs in JavaScript?
  

Hi folks,
I have done many different events in JavaScript. I am not able to know how to detect when scrolling occurs in JavaScript? And also please tell me how to use that as a JavaScript event. If you provide the sample of the code that would be much useful for me. So its a kind request to give some coding related to the topic. Hope that you guys will help me soon..!!

__________________
|===================|
|YAY if that made sense...|
|===================|
Reply With Quote
  #2  
Old 03-02-2010
Member
 
Join Date: Aug 2006
Posts: 235
Re: How to detect when scrolling occurs in JavaScript?

I think that you should set a boolean flag, whose move should be stopped after moving the screen programmatically. By doing this the scroll-listener would first check against that flag and then do the respective actions. Otherwise instead of inline on the body command, you can also add the event called onscroll during the document.onReady event. Doing something like I did might help you. Check this script :
Code:
<script language="javascript">
    document.observe('user:scrolling', function() { alert('Wow!'); });
</script>
...
<body onscroll="document.fire('user:scrolling')">
__________________
3.2 (northwood)
2gig ram
ATI AIW X800xt 256mb
Gigabyte GA-8knxp 875p Chipset
Optiwrite 8X DVD Burner
Win XP PRO Sp2 (Works Perfectly)
2 SATA Raptor 74gig Raid 0
2 7200 IDE 320gig HD
Reply With Quote
  #3  
Old 03-02-2010
Member
 
Join Date: Nov 2008
Posts: 996
Re: How to detect when scrolling occurs in JavaScript?

I know the code for the JavaScript that detects an an element after the scrolling takes place into view. For this coding I have used the Yahoo User Interface. Hope that you will get some useful thing from this coding.
Code:
var Event = YAHOO.util.Event;
var Dom = YAHOO.util.Dom;
Event.on(window, 'load', function() {
    var y = Dom.getY('ft');
    Event.on(window, 'scroll', function() {
        var top = (document.documentElement.scrollTop ?
            document.documentElement.scrollTop :
            document.body.scrollTop);
        var vpH = Dom.getViewportHeight();
        var coverage = parseInt(vpH + top);
        if ( coverage >= y ) {
            console.log('Now in view!!!');
        }
    });
});
Reply With Quote
  #4  
Old 03-02-2010
Member
 
Join Date: Mar 2008
Posts: 672
Re: How to detect when scrolling occurs in JavaScript?

You need to do the scrolling when you are having a large image that had to be scrolled both vertically and horizontally to view it properly. For doing this you will have to use the position scrolled to before the image map unloaded. And after this you will have to insert a cookie on the viewer's machine to store scrollbar positions. By doing this when you hit back, the cookie will automatically scrolled to the last position they were at in the image map (scrollTo()). Hope that you will get some hint from this explanation.
Reply With Quote
  #5  
Old 03-02-2010
Member
 
Join Date: May 2008
Posts: 2,383
Re: How to detect when scrolling occurs in JavaScript?

You should know that the browsers store the current position of both the vertical and horizontal scrollbars in JavaScript properties. You can determine where the viewer have scrolled on your page by accessing the properties of browser to retrieve the pixel values. The value of the vertical scrollbar in a property is stored in Internet Explorer. This property is called as "document.body.scrollTop". Also the property called "document.body.scrollLeft" stores the value of the horizontal scrollbar in Internet Explorer.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #6  
Old 03-02-2010
Member
 
Join Date: May 2008
Posts: 2,293
Re: How to detect when scrolling occurs in JavaScript?

I am giving you some steps that are necessary for the scrolling event in JavaScript :
  • You can use the scrollbar positions after making your own custom "events" by polling for a change in any JavaScript property.
  • The pixel value of vertical scrollbar position is stored in property "document.body.scrollTop" and on other hand the horizontal scrollbar position is in "document.body.scrollLeft". This is about an Internet Explorer.
  • In the Netscape, the pixel value of vertical scrollbar position is stored in property "window.pageYOffset" and the horizontal scrollbar position is in "window.pageXOffset".
  • You can use the function setInterval() with a second function in order to detect changes in properties.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to detect when scrolling occurs in JavaScript?"
Thread Thread Starter Forum Replies Last Post
Error occurs while connecting USB to the nokia C6-01 Siketan Portable Devices 6 07-06-2011 04:49 PM
Error code occurs when using webcam Potawatomi Hardware Peripherals 5 24-10-2010 05:30 AM
Help me to set up Windows Mail ( error occurs) leadye Technology & Internet 2 15-09-2009 08:33 AM
Problem to detect the javascript opener. garfield1 Software Development 3 29-06-2009 10:58 PM
Vertical scrolling...jumps rather than smooth scrolling - Excel 20 Abbie Vista Hardware Devices 2 24-04-2009 07:36 AM


All times are GMT +5.5. The time now is 11:55 PM.