Take the 2-minute tour ×

In Short: I am working on a project and I want to run a function when a particular div is displayed on the screen.

Detail: There is a scroll to top button fixed on the bottom right of the screen in my template. I want to hide that button when someone scroll down to the footer. Means when someone scroll down to the footer and the top border of the footer is displayed on the screen, I want a function to run which would hide the go to top button.

Please help me out of this problem...

share|improve this question
What have you tried so far? Can you show us some of your code? –  legendofawesomeness Oct 17 '11 at 16:48
possible duplicate of jQuery - Check if element is visible after scroling –  Andy E Oct 17 '11 at 16:51
if you choose to use one of the answers by attaching to the scroll event, make sure you also use or implement throttle or you might see some client performance degradation due to the event handler executing (probably) far more often than you want it to –  Kris Ivanov Oct 17 '11 at 17:30
I made this example in JsFiddle but I see it was answered: jsfiddle.net/e3xLd –  Arthur Wulf White Oct 17 '11 at 18:06
Thanks everyone for helping me. Especially Shusl and Arthur Wulf White –  Jawad Hyder Oct 18 '11 at 14:43
add comment

3 Answers

up vote 2 down vote accepted
$(document).ready(function() {
     var footer = $("footer");
     var f_top = footer.position().top;
      $(window).scroll(function() {
           if ($(window).scrollTop() + $(window).height() >= f_top ) {
share|improve this answer
add comment

Initialize the window to monitoring its scrolling

$(document).ready(function () {
    $(window).scroll(function () {
        // get the element that you want check scrolling on it
        var off = $("your-selector").offset().top; 
        var top = $(window).scrollTop() + $(window).height();
        if (off <= top) {
            // do your job
            // for example you can call a function like:

The function you want to invoke it:

function my_method_to_invoke() {
    // TODO
share|improve this answer
add comment

I think you'll need to register a scroll listener on the body that checks to see if the footer is in view and perform the hide if so. Something like this...

$(body).scroll(function () {

var scrollCheck = function () {
    var docTop, docBot, elemTop, elemBot;

    docTop = $(window).scrollTop;
    docBot = docTop + $(window).height();
    elemTop = $(<footer element>).offset().top;
    elemBot = elemTop + $(<footer element>).height();

    if ((elemBottom >= docTop) && (elemTop <= docBot)) {
         $(<button element).hide();
share|improve this answer
add comment

Your Answer


