I have a div element in html page located at position 1200px from top,now when user scroll page down or up and the div element is showing to user then a javascript function should call . and when again the page is scrolled up/down so that div is not visible then another function must be called.
Asked
Active
Viewed 89 times
-1
-
1Where is your code and try?? .... – DaniP Oct 23 '14 at 13:31
-
1Please post what you have tried so far. – Banana Oct 23 '14 at 13:33
-
@Banana Actually I don't know how to code when a div reaches at the top of the page by page scrolling . can you do this by jquery or css ? – Shakir.iti Oct 23 '14 at 13:38
-
2@Shakir.iti, a minimal effort and 2 minutes on google will give you the answer to that. please show some effort, and if you get stuck we will be happy to assist you. – Banana Oct 23 '14 at 13:41
-
Discussed at [MSO](http://meta.stackoverflow.com/q/274630/1169519). – Teemu Oct 23 '14 at 13:42
-
1@Shakir.iti please don't ask us to home work for you.. – Nishad K Ahamed Oct 23 '14 at 13:44
-
possible duplicate of [Check if element is visible after scrolling](http://stackoverflow.com/questions/487073/check-if-element-is-visible-after-scrolling) – dsgriffin Oct 23 '14 at 13:46
1 Answers
0
Use jQuery...
Snippet:
var $yourDiv = $('.your-div');
$(window).scroll(function(){
if ($(this).scrollTop() > 1200) {
$yourDiv.fadeIn();
} else {
$yourDiv.fadeOut();
}
});
API references:
- http://api.jquery.com/scroll/
- http://api.jquery.com/scrolltop/
- http://api.jquery.com/fadein/
- http://api.jquery.com/fadeout/
Example:

Alex Gill
- 2,395
- 1
- 16
- 18