5

Morning Guys,

Ok so I am using Bootstrap 3 to build my website - wanting to polish it off using the scrollTop smooth scroll on anchored tags. Cannot get it to work for the life of me.

So here is my code:

<script type="text/javascript" src="js/animate.js"></script>


<body>

<div id='imgDiv'>
    <div class="container">

        <center>
            <a href="#imgDiv2"><h2>my link</h2></a>

        </center>
    </div>  
</div>



<a href=""> 
<div id='imgDiv2'></div>
    some content here  
      </div>
    </div>
  </div>
</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>

This is the script inside animate.js

// JavaScript Document

$(document).ready(function() {
      $('a[href^="#"]').click(function() {
          var target = $(this.hash);
          if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]');
          if (target.length == 0) target = $('html');
          $('html, body').animate({ scrollTop: target.offset().top }, 500);
          return false;
      });
  });

So it does anchor to the div id named imgDiv2 but not using the smooth scrolling animation, any thoughts?

creimers
  • 4,975
  • 4
  • 33
  • 55
user3520443
  • 279
  • 2
  • 12

1 Answers1

4

You need to include animate.js after jQuery since your jQuery code inside animate.js require jQuery core library to work:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/animate.js"></script>
Felix
  • 37,892
  • 8
  • 43
  • 55
  • Worked - Thank you - I will mark the answer once it allows me to. – user3520443 May 09 '14 at 08:18
  • nothing should prevent you accepting an answer as the correct one, the voting button (up and down triangle) is one thing, the accept button is a big gray checkmark... – benomatis May 09 '14 at 08:21