Connecting Tech Pros Worldwide Help | Site Map

scroll buttons for div

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 05:34 PM
Jonathan
Guest
 
Posts: n/a
Default scroll buttons for div

I'm trying to build a scrollable div with "up" and "down" buttons to
replicate the action of a scroll bar. The reason I'm not just using
"overflow:auto" is because I want to position the scroll buttons on the
LEFT side of the box.

Don't ask why, I'm not the client ;)

Anyway, I've managed to get this working on some browsers by modifying
the scrollTop property of the div object, but it seems that this is
actually supposed to be read-only, and is inconsistent in any event.

Any ideas for how to do this cleanly?

-J



  #2  
Old July 23rd, 2005, 05:34 PM
Paul R
Guest
 
Posts: n/a
Default Re: scroll buttons for div

Jonathan wrote:[color=blue]
> I'm trying to build a scrollable div with "up" and "down" buttons to
> replicate the action of a scroll bar. The reason I'm not just using
> "overflow:auto" is because I want to position the scroll buttons on the
> LEFT side of the box.
>
> Don't ask why, I'm not the client ;)
>
> Anyway, I've managed to get this working on some browsers by modifying
> the scrollTop property of the div object, but it seems that this is
> actually supposed to be read-only, and is inconsistent in any event.
>
> Any ideas for how to do this cleanly?
>
> -J
>
>[/color]
If you put the contents inside two div tags you can use CSS to clip the
outer div and "scroll" the inner div by scripting its CSS "top" value, thus:

<html><head><style>
#contents{ position: relative; top: 0; left: 0; width: 100px; height: auto;}
#scrollable{ overflow: hidden; width: 100px; height: 100px; border: 1px
solid black;}
</style>
<script>
var t = 0;

function up()
{
t += 10;

with(document.getElementById("contents"))
{
if (t > 0)
t = 0;

if(style)
style.top = t + "px";
else
setAttribute("style", "top: " + t + "px");
}
}

function down()
{
t -= 10;

with(document.getElementById("contents"))
{
if(t < -clientHeight)
t = -clientHeight;

if(style)
style.top = t + "px";
else
setAttribute("style", "top: " + t + "px");
}
}
</script></head>
<body><table><tr><td><a href="javascript:void(0)"
onclick="up()">up</a></td><td rowspan="2"><div id="scrollable"><div
id="contents">scrolling content scrolling content scrolling content
scrolling content scrolling content scrolling content scrolling content
scrolling content scrolling content scrolling content scrolling content
</div></div></td></tr><tr><td><a href="javascript:void(0)"
onclick="down()">down</a></td></tr></table>
</body></html>
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.