Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I scroll a div field using javascript?

Posted on 2008-10-17
5
Medium Priority
?
990 Views
Last Modified: 2009-12-16
Hello experts, I have a web page with a large amount of information in a div field.  This page will be displayed on a small touch screen hand held and the default scroll buttons that come when you assign the property of overflow to a div tag are too small.  I am trying to use two buttons one to scroll up and the other to scroll down.  I have only been successful in scrolling to the top, I thought by substracting or adding to the scroll height would allow me to scroll using buttons.  Any ideas?


I know this still needs work, i will need to keep track of the current position.
function scroll_up()
{
  var div = document.getElementById('div-fork');
  h = div.scrollHeight;
  div.scrollTop = h-10;
}

function scroll_down()
{
  var div = document.getElementById('div-fork');
  h = div.scrollHeight;
  div.scrollTop = h+10;
}

<a onclick ="scroll_up();"><IMG alt="" src="images\arrowup.gif"></a><BR>
                                                      <BR>&nbsp;
                                                      <a onclick="scroll_down();"><IMG alt="" src="images\arrowdown.gif"></a></td>
                                    
0
Comment
Question by:tentavarious
  • 2
  • 2
5 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 22742537
use css   overflow:auto;
0
 
LVL 21

Expert Comment

by:silemone
ID: 22742554
or place anchors in page where when you click the button, it takes you to page anchor
0
 

Author Comment

by:tentavarious
ID: 22742595
I explained that overlow gives you a default scroll bar that is too small, this web page will be running on a touch screen and they want buttons to be able to scroll up or down through the list within the div tags.  Anchors will not work either.
0
 

Author Comment

by:tentavarious
ID: 22744628
What I want to happens is just like pressing the up and down arrow keys.  If I click on the div and press the down key it scrolls just like what I need.  Instead of actually pressing the arrow key I need a button on the form to do the same thing.  If I could send the the arrow key press to IE via javascript that would be perfect.
0
 
LVL 44

Accepted Solution

by:
scrathcyboy earned 1000 total points
ID: 22745755
http://germ.wordpress.com/2006/04/10/scroll-div-contents-with-javascript/
ub2.underblob.com/research/js/scroll_btn.php
orums.digitalpoint.com/showthread.php?t=945898
codingforums.com/archive/index.php?t-93997.html

Those should all help, but remember, small displays are a challenge any way you do it.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

972 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