Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery in page back button scrolling
    primarykey
    data
    text
    <p>I am looking to create a page that allows use of the back and forwards buttons for content within the page. I have accomplished the basic functionality using jQuery Address as featured at</p> <ul><li>http://www.asual.com/jquery/address</li></ul> <p>The issue I am having is how to get the callback function to work in coordination with jQuery scrollTo plugin to provide an animated back and forwards scrolling experience.</p> <pre><code>//Navigation between slides $('.nav-button').click(function(e) { e.preventDefault(); $.scrollTo($(this).attr('href'), 'slow', {easing:'easeInOutExpo'}); }); //Storage and activation of back and forwards attributes $('a').click(function() { $.address.value($(this).attr('href')); }); //Callback to scroll on back or forwards //NEED HELP HERE $.address.change(function(event) { $.scrollTo(event.value(), 'slow', {easing:'easeInOutExpo'}); }); </code></pre> <p>As Im sure you can see the problem really isnt that difficult, but since Im still learning it is out of the scope of my knowledge. Any help is much appreciated.</p> <p>All of the content is contained within one page divided into different "pages" by the use of various div elements with a common class</p> <p><strong>UPDATE:</strong></p> <p>I created a fiddle to display the issue more clearly.</p> <p>jsfiddle.net/d7uZ7/6</p> <p>The bottom section of jquery is what is to be used to trigger the scrolling after a back or forward page event</p> <p><strong>SOLUTION:</strong></p> <p>So after a long time battling with this a solution (of sorts) has been found. Also, I should not that without the chat with <em>JacobMcLock</em> none of this would have been possible.</p> <p>Anyhow, the last section of my original post should be changed to one of the two following code blocks</p> <pre><code>//Method 1 $.address.change(function (event) { var value = event.value, i = value.indexOf('#'), $element = (i === -1) ? $("body") : $(value.substr(i, value.length-1)); $.scrollTo($element, 'slow', {easing:'easeInOutExpo'}); }); //Method 2 $(window).on('hashchange', function(event) { event.preventDefault(); $.address.change(function (event) { var value = event.value, i = value.indexOf('#'), $element = (i === -1) ? $("body") : $(value.substr(i, value.length-1)); $.scrollTo($element, 'slow', {easing:'easeInOutExpo'}); }); }); </code></pre> <p>Use the first block for the best speed, but with lack of compatibility. This will function as desired in Chrome and Safari and will be glitchy in others. This is because they handle <code>hashchange</code> and <code>popstate</code> events correctly while others do not. Oddly some older browsers will also work properly.</p> <p>The second method, while much slower (there is a notable delay on animation start), will work in almost all browsers semi-well. Yep, just semi-well, sometimes it still fails. So the reality is that due to browsers not using these tags correctly youre likely stuck with boring old non-animated back and forward in page transitions. So sad. Unless you feel like doing a monumental amount of coding.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload