Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: JavaScript
Expertise: Intermediate
Aug 15, 2005

Text Scrolling on a Click Event

This code scrolls the text left and right on the click event of < , >:

<html>
<head>
<script language="javascript">
   function ScrollBy(dir){
        var left = xdiv.scrollLeft;
        if (dir =='left')
           xdiv.scrollLeft = left - 30;
        else
           xdiv.scrollLeft = left + 30; 
   }
</script>
</head>
<body>
<table>
<tr>
<td><a onclick="ScrollBy('left'); return false" title="Click to scroll left side"><</a>
</td>
<td>
<div id="xdiv" style="overflow-x:hidden;width=150px;Height=10px">
<table><tr><td  bgcolor='yellow'>Yellow</td><td bgcolor='red'>
Red</td><td bgcolor='green'>Green</td><td bgcolor='blue'>Blue</td>
<td bgcolor='cyan'>Cyan</td>
</tr>
</table>
</div>
</td>
<td><a onclick="ScrollBy('right'); return false" title="Click to scroll right side">></a></td>
</tr>
</table>
</body>
</html>
Santhi Maadhaven
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap