4

I've been making a website that uses parallax very similar to how it's used in http://keithclark.co.uk/articles/pure-css-parallax-websites/demo3/, and I've been trying to implement some jquery which will make the page automatically scroll to the bottom on page load. However, the command I am using does not move the scroll bar at all. I've tried this on static websites and it seems to work fine.

$(document).ready(function() {
  $("html, body").animate({
      scrollTop: $(document).height()
    }, 2000);
  return false;
});

My code (stripped of text) is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link href='https://fonts.googleapis.com/css?family=Arvo' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<style>
  .email a {
    color: #001F67;
    text-decoration: none;
  }

  a {
    text-decoration: none;
  }

  .title {
    text-align: center;
    position: absolute;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    color: Black;
    font-size: 6vmin;
  }

  .About {
    text-align: center;
    position: absolute;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    color: #001F67;
    text-decoration: none;
    font-size: 4vmin;
    background-color: white;
  }

  .parallax {
    height: 500px; 
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-perspective: 300px;
    perspective: 300px;
  }

  .parallax__group {
    position: relative;
    height: 500px; 
    height: 100vh;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
  }

  .parallax__layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }

  .parallax__layer--fore {
    -webkit-transform: translateZ(90px) scale(.7);
    transform: translateZ(90px) scale(.7);
    z-index: 1;
  }

  .parallax__layer--base {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    z-index: 4;
  }

  .parallax__layer--back {
    -webkit-transform: translateZ(-300px) scale(2);
    transform: translateZ(-550px) scale(3);
    z-index: 3;
  }

  .parallax__group {
    -webkit-transition: -webkit-transform 0.5s;
    transition: transform 0.5s;
  }

  body, html {
    overflow: hidden;
  }

  body {
    font: 100% / 1.5 Arvo;
  }

  * {
    margin:0;
    padding:0;
  }

  .parallax {
    font-size: 200%;
  }

  #group2 {
    z-index: 3;
  }

  #group2 .parallax__layer--back {
    background: #FFFFFF;
  }

  #group3 {
    z-index: 4;
  }

  #group3 .parallax__layer--base {
    /*background: black;*/
  }
</style>
<script>
$(document).ready(function() {
  $("html, body").animate({
      scrollTop: $(document).height()
    }, 2000);
  return false;
});
</script>
</head>
<body>
  <div class="parallax">
    <div id="group2" class="parallax__group">
      <div class="parallax__layer parallax__layer--base">
      </div>
      <div class="parallax__layer parallax__layer--back">
        <div class="title"><strong>Example Text</strong></div>
      </div>
    </div>
    <div id="group3" class="parallax__group">
      <div class="parallax__layer parallax__layer--fore">
        <div class="About">
          <!-- design inspired by graham hicks -->
          <p>
            Example Text
          <p>
            Example Text
          </p>
          <p class = "email">
            <br /> Example Text 
          </p>
        </div>
      </div>
      <div class="parallax__layer parallax__layer--base">
      </div>
    </div>
  </div>
</body>
</html>

Does anyone have any idea as to why this isn't working?

Jongware
  • 21,058
  • 8
  • 43
  • 86
keynesian
  • 41
  • 5

1 Answers1

5

Change $("html, body") to $(".parallax") to get it working.

$(document).ready(function() {
  $(".parallax").animate({
      scrollTop: $(document).height()
    }, 2000);
  return false;
});

JSFiddle: https://jsfiddle.net/qs0vbbtx/

Nerdwood
  • 3,725
  • 1
  • 17
  • 19
  • Hmm, that didn't work. I think you're onto something though. – keynesian Oct 09 '15 at 03:30
  • I set up a local test for this and got it to automatically scroll by just changing the jQuery selector. I'll post the full jQuery code sample just to make sure you've got what I used. – Nerdwood Oct 09 '15 at 03:35
  • Nice! Glad I could help. :) – Nerdwood Oct 09 '15 at 03:42
  • 1
    Stackoverflow noob here. How can I give you reputation/points for your help? I don't have 15 rep yet so I can't upvote – keynesian Oct 09 '15 at 03:43
  • That's fine. Marking it as an accepted answer is the main thing - that'll help other people when looking for a solution. :) – Nerdwood Oct 09 '15 at 03:48