PDA

View Full Version : Virtual Pagination script v2.1: scroll back to top



fng
02-15-2011, 03:37 PM
1) Script Title: Virtual Pagination script v2.1

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/virtualpagination.htm

3) Describe problem: The script works like a charm, however, when i click the next or page number, the page doesn't scroll back to the top of the page. It stays exactly where it is. It's a bit annoying, because as a visitor you're scrolling trough the list, click the next page at the bottom and then you're at the bottom of the next page, not at the top as usual.

ddadmin
02-15-2011, 09:25 PM
There are a couple of threads on this already, for example: http://www.dynamicdrive.com/forums/showthread.php?t=18210

fng
02-16-2011, 01:11 PM
I am sorry, thank you for the reply.

I replaced the lines you mentioned to the code below, but now it scrolls even more to the bottom. I'd like it to scroll to the top.

for (var i=0; i<totalitems; i++)
{
if (i>=showstartindex && i<=showendindex)
{
this.pieces[i].style.display="block"
if (this.pieces[i].scrollIntoView)
this.pieces[i].scrollIntoView()
}
else
{
this.pieces[i].style.display="none"
}
}


I am also getting an error-message:

Webpage error details
Message: 'document.getElementById(...)' is null or not an object
Line: 85
Char: 3
Code: 0
URI: virtualpaginate.js

ddadmin
02-17-2011, 07:32 PM
Hmm you might have mis-copied something. Try the below attached .js file instead. To recap, it should jump the user back to the top of the virtual pagination content each time the navigation link is clicked on, ensuring even long content are seen from the very top downwards each time.

fng
02-18-2011, 04:07 PM
I appreciate all your help.

Its not working. It stays on the bottom all the time. Did i perhaps erase something in the HTML, like a div name or something? Or has it perhaps something to do with the fact that the pagebrowserbuttons are on the bottom of the page (and not at the top)?

I am just guessing, I am worthless in JS.

Again thanks for all your help!

fng
02-24-2011, 03:17 PM
Sorry for the bump, but does anyone has anymore suggestions?

ddadmin
02-25-2011, 08:12 AM
Please post a link to the page on your site that contains the problematic script with the modified .js file in place so we can check it out.

fng
03-01-2011, 12:39 PM
One of the problems is solved!

Instead of scrollintoview i had to use window.scrollTo(0,0). You mentioned that in your post and it seems to work like a charm.

The other problem is a JS-error that only seems to occur in Iexplorer:

Webpage error details
Message: 'document.getElementById(...)' is null or not an object
Line: 85
Char: 3
Code: 0
URI: virtualpaginate.js

I know you asked me for a link, but i don't have the site online (yet). I have it running on an intranet and all content is loaded dynamically from a database. If you really need it to solve the issue, i'll ofcoarse look for a host and place it online.

ddadmin
03-01-2011, 08:14 PM
Hmm without an online example of the problem that error you posted above is simply too vague. Can you simply attach the modified .js file here?