2

I'm looking to make a div appear when a page is scrolled down. The thing is that my page body has overflow hidden as well as most of other divs except the table that appears at some point on the page when the button is pressed. So that table has overflow:scroll as needed and I try to hook that scroll event on it. But it doesn't work anyway. What can it be?

Here is my html:

<body>  
  <div class="maine">
<table id="tableToClone" class="ts">
  <div class="backtotopplank"></div>
                    </table>  
  </div>   
</body>

CSS:

html, body{
  height:100%;
  background:black;
  width:100%;
}

.ts  {  
  background:red;
    border-collapse:collapse;
    border-spacing:0;
  margin:auto auto;
    width:70%;
  height:3000px;
    overflow:scroll;
}


.maine{
  width:70%;
  margin:auto auto;
  background:white; 
  position:relative;
    overflow-x:hidden;  
}

.backtotopplank{
    background:black;
    background-size:100% 100%;
    position:fixed;
    width:153px;
    height:56px;
    left:900px;
    bottom:0px;
    cursor: pointer;
display:none;
}

And JQuery:

$(".ts").scroll(function() {
  var y = $(this).scrollTop();
  if (y > 400) {
    $(".backtotopplank").fadeIn();
  } else {
    $(".backtotopplank").fadeOut();
  }
});
3
  • I check code and come to find that its window that scrolling not table with class 'ts'. Try window instead of the class 'ts'. Try $(window).scroll instead of $('.ts').scroll Commented Oct 29, 2015 at 1:21
  • A problem is that on my page I tried both window and document and it doesn't work. Commented Oct 29, 2015 at 1:24
  • Please check I just added an answer for this Commented Oct 29, 2015 at 1:29

1 Answer 1

3
$(document).ready(function()
{
  $(window).scroll(function() {
    var y = $(this).scrollTop();
    if (y > 100) {
     $(".backtotopplank").fadeIn();
    } else {
     $(".backtotopplank").fadeOut();
   }
  });
});

Try this It might Help you. It work for me.

Sign up to request clarification or add additional context in comments.

1 Comment

Man you are amazing, it was that simple, just including document ready! Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.