Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Control list scroll position on load.

Posted on 2013-02-04
7
Medium Priority
?
472 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 2000 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 2000 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
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to dynamically set the form action using jQuery.

705 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