Solved

Reset Scrollbar of Layer Onclick

Posted on 2003-11-19
2
892 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

713 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