I've been working on this scenario for a couple hours and I'm finally at a loss. I'm pretty sure I've seen this done before, but it may not be possible and I'd hate to waste more time if it's not even possible.
I would like to click a button, load a new url, then after the document is ready I would like it to automatically smooth scroll to a specified location on that page using animate (so it scrolls smooth and I can control the transition speed).
I thought something like this would work. I might be close but no cigar!
JS:
$("#backToWorkBtn").click(function() {
window.location.href = "index.php";
$(window).on("load", function () {
$('html,body').animate({
scrollTop: $("#workSection").offset().top
}, 800);
});
});
I have also tried...
$("#backToWorkBtn").click(function() {
window.location.href = "index.php";
$(document).ready(function() {
$('html,body').animate({
scrollTop: $("#workSection").offset().top
}, 800);
});
});
HTML:
below is on gallery.php
<a id="backToWorkBtn">BACK TO MY WORK</a>
below is on index.php
<section id="introSection">
Intro Area
</section>
<section id="aboutSection">
About Me Area
</section>
<section id="workSection">
<a href="gallery.php">Web Design</a>
<a href="gallery.php">Print Design</a>
etc etc etc..
</section>