Solved

Control list scroll position on load.

Posted on 2013-02-04
7
455 Views
Last Modified: 2013-11-19
This is a follow-up to my earlier question (#27928418).

The attachment to this question is a screen capture of a web page I am working on which contains an area where a list of songs is displayed. Also displayed is the music notation of a song which the user has selected. The music notation is in an iframe. Clicking on a song title loads its notation into the frame without reloading the parent page. The HTML source code is also attached. This page is the result of a previous page where the song list is displayed. When the user selects a song title, it links to this notation page where the song list is redisplayed alongside the musical notation of the selected song.

The song list can vary in length from one song to several hundred titles. Once the length of the list exceeds the height of the space allotted to it, the right scroll bar appears, allowing the user to scroll down to view additional songs on the list. The problem is the user may have selected a song far down the list. When the page loads, by default, the topmost portion of the list is displayed.

When this notation page loads, I would like the list to be scrolled to the position where the selected song title is at the top of the displayed titles. It should still be in its correct position relative to its neighboring song titles, but should appear at the top of the visible portion of the list, just as if it were scrolled to that position. The user could then scroll up or down from there to review additional titles. My client is adamant that I not use a paging system, so I must retain the scroll format. Also, the client likes the look as it is, so any solution should contain no additional controls (or at least minimize them).

The information about each song is contained within a div having and id of “key” plus the number equal to its position in the array of songs in the list, e.g. key23 is the id for the 24th song in the list.

Is there a way to do this?
Sample-Screenshot.png
CCS-Song-Library.htm
0
Comment
Question by:gpinzino
  • 4
  • 3
7 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 500 total points
ID: 38853204
Well if you have an id then just target the id in the url and it will be positioned at the top.

http://mysite.com/mypage.html#key23 

will put the element with id 'key23' at the top.

Cd&
0
 
LVL 1

Author Comment

by:gpinzino
ID: 38855552
Thanks COBOLdinosaur. It works well on the list. Unfortunately, it also pulls down the entire page so you do not see the top banner and navigation.  Is there a way to move the page back up so you can see what's at the top of the page?
0
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 500 total points
ID: 38856180
Well you could try this:
http://clifgriffin.com/2008/10/14/using-javascript-to-scroll-to-a-specific-elementobject/

But I don't know how reliable it will be using an iframe.

You might be better to use window.scrollTo(0,0) in the main page after loading the iframe.

Cd&
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:gpinzino
ID: 38856227
I was thinking the scrollTo might be an option here. I will check out both and let you know.
0
 
LVL 1

Author Comment

by:gpinzino
ID: 38856323
I got it on the first try. Really quite simple.

In the <script>, I added:
function showIt(elID) {
      var el = document.getElementById(elID);
      el.scrollIntoView(true);
}

And then I modified my <body> tag to read:
<body id="bodyId" onload="showIt('bodyId')">

That's it. When the page loads, it jumps right to the top!
0
 
LVL 1

Author Closing Comment

by:gpinzino
ID: 38856336
Great job, COBOLdinosaur. Thanks!
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38856469
:^) Great! I'm glad you have it working.

Cd&
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question