Results 1 to 3 of 3

Thread: Scrolling an IFRAME sideways with (java)Script

  1. #1
    Join Date
    Sep 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Scrolling an IFRAME sideways with (java)Script

    Hello,

    I would like to scroll the content of an IFRAME sideways instead of up and down.

    The up and down version I figured out, but how can i adjust the existing script to make it scroll from left to right and vice versa untill it reaches the end of the div or table?

    Code:
    <script type="text/javascript">
    
    var timer_id;
    function scroll_iframe(frm,inc,dir) {
      if (timer_id) clearTimeout(timer_id);
      if (window.frames[frm]) {
        if (dir == "v") window.frames[frm].scrollBy(0, inc);
        else window.frames[frm].scrollBy(inc, 0);
        timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 20);
      }
    }
    
    function stopScroll() { if (timer_id) clearTimeout(timer_id); }
    </script>
    and then the button script:

    Code:
    <a href="javascript:;" onmouseover="scroll_iframe('scr1', -4, 'v'); window.status='Up.'; return true" onmouseout="stopScroll(); window.status=''; return true">
    and

    Code:
    <a href="javascript:;" onmouseover="scroll_iframe('scr1', 4, 'v'); window.status='Down.'; return true" onmouseout="stopScroll(); window.status=''; return true">
    Thanks!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <a href="javascript:;" onmouseover="scroll_iframe('scr1', -4, 'v'); window.status='Up.'; return true" onmouseout="stopScroll(); window.status=''; return true">Up</a>
    <a href="javascript:;" onmouseover="scroll_iframe('scr1', 4, 'v'); window.status='Down.'; return true" onmouseout="stopScroll(); window.status=''; return true">Down</a>
    <a href="javascript:;" onmouseover="scroll_iframe('scr1', -4, 'h'); window.status='Left.'; return true" onmouseout="stopScroll(); window.status=''; return true">Left</a>
    <a href="javascript:;" onmouseover="scroll_iframe('scr1', 4, 'h'); window.status='Right.'; return true" onmouseout="stopScroll(); window.status=''; return true">Right</a>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Here is an even better way to do it:

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    .scrd {
    cursor:pointer;
    color:blue;
    text-decoration:underline;
    }
    </style>
    <script type="text/javascript">
    
    var timer_id;
    function scroll_iframe(frm,inc,dir) {
      if (timer_id) clearTimeout(timer_id);
      if (window.frames[frm]) {
        if (dir == "v") window.frames[frm].scrollBy(0, inc);
        else window.frames[frm].scrollBy(inc, 0);
        timer_id = setTimeout("scroll_iframe('" + frm + "'," + inc + ",'" + dir + "')", 20);
      }
    }
    
    function stopScroll() { if (timer_id) clearTimeout(timer_id); }
    </script>
    </head>
    <body>
    <iframe name="scr1" src="../side/1st.jpg" width="400" height="400" scrolling="no" frameborder="1"></iframe><br>
    <span class="scrd" onmouseover="this.style.color='red';scroll_iframe('scr1', -4, 'v'); window.status='Up.'; return true" onmouseout="this.style.color='';stopScroll(); window.status=''; return true">Up</span>
    <span class="scrd" onmouseover="this.style.color='red';scroll_iframe('scr1', 4, 'v'); window.status='Down.'; return true" onmouseout="this.style.color='';stopScroll(); window.status=''; return true">Down</span>
    <span class="scrd" onmouseover="this.style.color='red';scroll_iframe('scr1', -4, 'h'); window.status='Left.'; return true" onmouseout="this.style.color='';stopScroll(); window.status=''; return true">Left</span>
    <span class="scrd" onmouseover="this.style.color='red';scroll_iframe('scr1', 4, 'h'); window.status='Right.'; return true" onmouseout="this.style.color='';stopScroll(); window.status=''; return true">Right</span>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •