Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 896
  • Last Modified:

Reset Scrollbar of Layer Onclick

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
rabbits2
Asked:
rabbits2
  • 2
1 Solution
 
FragMaster_BCommented:
Stick this line into at the end of your MM_swapImage() function.

[code]
window.setTimeout("document.getElementById('Layer2').scrollTop = 0", 200)
[/code]
0
 
FragMaster_BCommented:
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now