Hello Forum!

I'm new here and also pretty bad at writing javascript. I'm using a snippet
of code by Lloyd Irvin
(http://agyuku.net/2009/05/back-to-top-link-using-jquery/) that allows the
user to scroll back to the top of the page by clicking on a fixed button
that fades in only when you begin scrolling down the page. It's a great code
and I'm trying to rewrite it partially so instead of scrolling to the top it
scrolls to a another section of the website.

This is the original snippet of code from Lloyd:
<script>
        jQuery(function() {
                jQuery(this).pngFix();
                jQuery(window).scroll(function() {
                        if(jQuery(this).scrollTop() != 0) {
                                jQuery('#toTop').fadeIn();      
                        } else {
                                jQuery('#toTop').fadeOut();
                        }
                });
                
                jQuery('#toTop').click(function() {
                        jQuery('body,html').animate({scrollTop:0},800);
                });     
        });
</script>

The script works with this div: <div id="toTop">^ Back to Top</div>.

And here's mine, which is the same except that I replaced the "0" position
to "500":

<script>
        jQuery(function() {
                jQuery(this).pngFix();
                jQuery(window).scroll(function() {
                        if(jQuery(this).scrollTop() != 500) {
                                jQuery('#toTop').fadeIn();      
                        } else {
                                jQuery('#toTop').fadeOut();
                        }
                });
                
                jQuery('#toTop').click(function() {
                        jQuery('body,html').animate({scrollTop:500},800);
                });     
        });
</script>

Now my question. At this point, the button disappears only when the user hit
the 500 mark. I would like it to disappear and stay invisible when the user
reaches the 500 mark and anything below. I think it's got to do with this
line: if(jQuery(this).scrollTop() != 500) but I just don't know the right
"wording".

Also, at this point, when the page loads, the button doesn't show unless you
start scrolling down. Is there a way to make it appear when the page loads?

I think this is all pretty simple stuff for you developers. It's just too
much for me at this point. I would appreciate your input and advice.

Thanks!
-- 
View this message in context: 
http://old.nabble.com/Simple-jQuery-question-tp26443552s27240p26443552.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to