Solved

How can I scroll a div field using javascript?

Posted on 2008-10-17
5
986 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
[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
  • 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 250 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

628 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