Solved

Reset Scrollbar of Layer Onclick

Posted on 2003-11-19
2
889 Views
Last Modified: 2012-05-04
I have a htm page layed out in dreamweaver, using one layer to house the menu system ,madeup of gif images with behaviors attached, and another layer which holds an image.  This layer holding the image is set to auto scroll.  What i want to happen is to click through the menu and onCLick of each button the iamge to change in layer two.  This is working fine, the problem I have is that iwth some images you need to scroll down to view it all, but if I scroll down and then click a diff button to view a new image the scrollbar of this layer which houses the images remains scrolled down when I wish it to reset on click to the top.
Below is my code for you to see:


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" onLoad="MM_preloadImages('images/menu_ourcompbig.gif','images/menu_meet9_f2.gif','images/txt_london.gif','images/txt_consumer.gif')">
<div id="Layer1" style="position:absolute; left:119px; top:50px; width:203px; height:330px; z-index:1"><a href="#" onClick="MM_swapImage('Image1','','images/menu_ourcompbig.gif','txt','','images/txt_consumer.gif',1)"><img name="Image1" border="0" src="images/menu_ourcomp1.gif" width="317" height="36"></a><a href="#" onClick="MM_swapImage('Image3','','images/menu_meet9_f2.gif','txt','','images/txt_london.gif',1)"><img name="Image3" border="0" src="images/menu_meet9.gif" width="317" height="28"></a></div>
<div id="Layer2" style="position:absolute; left:454px; top:49px; width:508px; height:200px; z-index:2; overflow: auto"><img src="images/txt_consumer.gif" width="429" height="474" name="txt"></div>
</body>
</html>

Many thanks for your help..
0
Comment
Question by:rabbits2
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
FragMaster_B earned 500 total points
ID: 9779890
Stick this line into at the end of your MM_swapImage() function.

[code]
window.setTimeout("document.getElementById('Layer2').scrollTop = 0", 200)
[/code]
0
 
LVL 1

Expert Comment

by:FragMaster_B
ID: 9779910
here's what the function should look like when you're done...

[code]
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

  window.setTimeout("document.getElementById('Layer2').scrollTop = 0", 200)
}
[/code]

You may not need this stuff wrapped in a setTimeout, but it's probably safer this way.

Hope this is what you're looking for,
-Frag
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

910 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now