Welcome to WebmasterWorld Guest from 54.196.175.173

Forum Moderators: open

Message Too Old, No Replies

How to prevent button on the page loading?

     

toplisek

12:47 pm on Jan 25, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



How to prevent button on the page loading?

I have code like:
<script type="text/javascript">
jQuery(document).ready(function(){

jQuery(window).scroll(function(){
if (jQuery(this).scrollTop() != 0) {
jQuery('.mybutton1').fadeIn();
} else {
jQuery('.mybutton1').fadeOut();
}
});

jQuery('.mybutton1').click(function(){
jQuery("html, body").animate({ scrollTop: 0 }, 850);
return false;
});

});
</script>

What will influence != 0 or > 100 and why is button showing when I load page but when I scroll it will work?
Need help.

Fotiman

2:11 pm on Jan 25, 2013 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



You're attaching an event listener to the window's scroll event. When the page first loads, that event won't be fired, so you need to also repeat that functionality in the ready method.

jQuery(document).ready(function () {

if (jQuery(window).scrollTop() != 0) {
jQuery('.mybutton1').fadeIn();
} else {
jQuery('.mybutton1').fadeOut();
}

jQuery(window).scroll(function () {
if (jQuery(this).scrollTop() != 0) {
jQuery('.mybutton1').fadeIn();
} else {
jQuery('.mybutton1').fadeOut();
}
});

jQuery('.mybutton1').click(function () {
jQuery("html, body").animate({
scrollTop: 0
}, 850);
return false;
});

});

toplisek

8:12 am on Jan 29, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



It works perfect.
1. What will influence != 0 or > 100
2. Is it correct placement of this javascript as Jquery plugin file/folder or it can be pure javascript file even this is jQuery?

toplisek

8:50 am on Jan 30, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



3. How to show button or footer when there is scrolled to the the end (bottom)? Is there any setting to do it in the correct way with Jquery modification?

Fotiman

2:10 pm on Jan 30, 2013 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



1. [api.jquery.com...]

The vertical scroll position is the same as the number of pixels that are hidden from view above the scrollable area. If the scroll bar is at the very top, or if the element is not scrollable, this number will be 0


2. This script does not need to be a jQuery "plugin", but does require jQuery, so as long as you include jQuery first, you can put this in a regular script file.

3. That could be tricky. What if someone doesn't need to scroll at all (ie - they have massive monitor/resolution that can fit everything without scrolling)? Why not just put the button/footer at the bottom? That way, when the user gets there, they will have already seen and/or scrolled down through the content.

toplisek

7:57 pm on Jan 30, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



You are right. Usability issue can be seen if this happens. I gues they detect also resolution to pass this particular issue.

I'm nor sure about your URL:
[api.jquery.com...]

It is not quoted my value:
What will influence != 0 or > 100
It is the current vertical position of the scroll bar for each of the set of matched elements.More than 100px position from the top.Yes?
What is than !=0 ?

Fotiman

8:32 pm on Jan 30, 2013 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



If scrollTop == 0, the scroll bar is at the very top, or the element is not scrollable. If the element is scrollable, and it is scrolled down more the 100px, then that would match the case of scrollTop() > 100.

toplisek

3:55 pm on Feb 1, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



What is than != 0 as definition?

Fotiman

5:02 pm on Feb 1, 2013 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



not equal to zero.

toplisek

7:26 pm on Feb 2, 2013 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Thanks for your reply.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month