Current location: Hot Scripts Forums » General Web Coding » JavaScript » add extra var


add extra var

Reply
  #1 (permalink)  
Old 03-05-07, 08:16 AM
jonnekke jonnekke is offline
Code Guru
 
Join Date: Oct 2005
Location: holland!
Posts: 704
Thanks: 0
Thanked 0 Times in 0 Posts
add extra var

How can I add:

var targBox2 = "box2";

to this script so it would work?...


javascript Code:
  1. var targBox = "box";
  2.  
  3. function init() {
  4.     if (document.getElementById) {
  5.         var atags = document.getElementsByTagName("A");
  6.         for (var i=0;i<atags.length;i++) {
  7.             var ca = atags[i];
  8.             if (ca.href.indexOf("#") > -1) {
  9.                 ca.onclick = function() {
  10.                     scrollDivToAnchor(this.href.split("#")[1]);
  11.                 }
  12.             }
  13.         }
  14.     }
  15. }
  16.  
  17. function scrollDivToAnchor(a) {
  18.  
  19.     var b = document.getElementById(targBox);
  20.     b.scrollTop = document.getElementById(a).offsetTop - b.offsetTop;
  21.  
  22.     // alternately, if your elements are not nested within other nodes inside the box,
  23.     // you could use document.getElementById(a).parentNode.scrollTop
  24.     // that way you wouldn't need to specify the id of the scrollable box
  25.  
  26. }
  27.  
  28. if (navigator.userAgent.indexOf("Safari") > -1) {
  29.     window.onload = init;
  30. }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-05-07, 08:36 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Try.
javascript Code:
  1. var targBox2 = "box2";
  2.  
  3. function scrollDivToAnchor(a) {
  4.  
  5.     var b = document.getElementById(targBox);
  6.     b.scrollTop = document.getElementById(a).offsetTop - b.offsetTop;
  7.  
  8.     var c = document.getElementById(targBox2);
  9.     c.scrollTop = document.getElementById(a).offsetTop - c.offsetTop;
  10.     // alternately, if your elements are not nested within other nodes inside the box,
  11.     // you could use document.getElementById(a).parentNode.scrollTop
  12.     // that way you wouldn't need to specify the id of the scrollable box
  13.  
  14. }

And you might as well take a look at the comment. That could help too.
Quote:
// alternately, if your elements are not nested within other nodes inside the box,
// you could use document.getElementById(a).parentNode.scrollTop
// that way you wouldn't need to specify the id of the scrollable box
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
RSS Using RSS2Html Script VKX PHP 1 10-16-06 06:27 PM
Paypal Generator Hunter JavaScript 1 08-06-06 08:49 AM
link to iframe//help moose JavaScript 1 01-29-05 01:26 PM
Help with dynamic select in dynamic table noviceforever JavaScript 1 06-23-04 02:20 PM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 11:15 AM


All times are GMT -5. The time now is 12:14 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.