Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Customization history.state #54

Open
uinz opened this issue Dec 8, 2015 · 0 comments
Open

Customization history.state #54

uinz opened this issue Dec 8, 2015 · 0 comments

Comments

@uinz
Copy link

uinz commented Dec 8, 2015

Hi, I have a problem

I want to store #main-container(overflow:scroll)'s scrollTop,
that when I click browser's back button, I can use it to set scrollTop.

But, I find I can't write anything in history.state, it will rewrite by turbolinks

> history.state.scrollTop = 200`
< Object {turbolinks: true, url: "http://localhost:3000/",scrollTop:200} 

change page and back

> history.state
< Object {turbolinks: true, url: "http://localhost:3000/"} 

I had to use localStorage

      $(document).on('page:before-change', function(){
        localStorage[location.pathname] = $('.main-container').scrollTop();
      })
      $(document).on('page:change', function(e){
        $('.main-container').scrollTop(localStorage[location.pathname])
      })

how cant I use history.state to do this ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant