Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving position in Horizontal Div Scroller

Status
Not open for further replies.

minli98

IS-IT--Management
Joined
Aug 30, 2005
Messages
178
Location
US
Hi,

I am trying to create a css-based horizontal div scroller (a div that allows user to scroll the content left and right).

Here's what I have:
Code:
#window{
 position:relative;
 border:solid 2px;
 width:760px;
 height:330px;
}
#windowscroll{
 top:0px;
 left:0px;
 margin:0;
 padding:0;
 overflow:auto;
}
#content{
 margin:0;
 padding:0;
}

<div id="window">
  <div id="windowscroll">
    <div id="content">
        Item1...Item2...Item3...Item4 ...
    </div>
  </div>
</div>

This scroller works fine, but here's my problem: say a user scrolls to the right, and sees an item that she likes. She clicks on it and is taken to the page for that item. I would like to save in a cookie the position of the scroller (how far to the right she has scrolled to just before exiting the page), so that when she returns to the page, she will be taken back to where she was.

My question is what element controls how far to the right she has scrolled to? Say she has scrolled 200px to the right, when she returns to the page what element shall I set to 200px in order to return her to her last position?

I would have thought, it should be the left=-200px in #content, but it doesn't work for me. Any suggestion?

Regards,
Min
 
Pull the scrollLeft value from the div when the page is submitted, and reset the same value after the page has reloaded.

Code:
[B][I]when submitting:[/I][/B]
cookievalue = document.getElementById("divName").scrollLeft;


[B][I]on page reload[/I][/B]
document.getElementById("divName").scrollLeft = cookieValue;

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
Hi Kaht,

Thank you for your help. I managed to get it working for IE6.0, but I notice an annoying quirk with Firefox (1.0.7).

I've uploaded a sample to
To illustrate the quirk, do the following:
1. Scroll to the right up to a point where the scrollbar is just below Widget 10.
2. Click on Widget 10.
3. Go back to the previous page

Notice that the scrollbar position has now shifted to the left. And when you move the scrollbar, you can see that the content div suddenly shifts to the left and re-aligns with the scrollbar.

Any idea how I can fix this?

Regards,
Min
 
Don't cache your pages?

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
I don't think we can afford to not cache the pages, as this would be a main page that users repeatedly hit.

Any other suggestions?
 
Unfortunately, yes. Haven't had the time to install v1.5, but if I can't fix it for 1.0.7 then I don't think I can use it. I don't think the majority of people have upgraded yet.

Min
 
Dan,

I changed scrollLeft to pageXOffset, but unfortunately the problem is still there.

Min
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top