Arjen M
Arjen M

Reputation: 123

Smooth scroll and dynamic page

I'am almost finished with my website and now i have one issue.

on my page i got 3 blocks with tekst. 2 are static one is dynamic.

When clicked on a button the page should change, this is working fine. but now i added smooth scroll to my website.

The smooth scroll works fine. but now the dynamic page change doesn't work anymore.

i looks like one thing is over ruling the other.

How can i solve this?

Here is my code.

i have created on the index.php

  <?php

      $page = 'home'; 

    $pages = array( 'home' , 'hoogopgeleid', 'kennis' , 'extern', 'uitstroom', 'dynamiek' , 'didacticum');

    if( in_array( $_GET['page'], $pages ) ) {
        $page = $_GET['page'];
    }

    ?>

For the smooth scroll i used (found on the internet)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(function() {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});
</script>

and in my button is use the link

<button> <a href="?page="home#pro"> Here some tekst </a>  </button>

Also on the internet i read about the home#pro. but like i said, only one is working.

I think and hope it will be a simple solution!

Thnx

Upvotes: 0

Views: 393

Answers (1)

Tom Walters
Tom Walters

Reputation: 15616

Remove:

return false;

As this prevents the default browser behaviour and is probably preventing the propagation to your dynamic-content loader.

Upvotes: 1

Related Questions