Solved

Reset Scrollbar of Layer Onclick

Posted on 2003-11-19
2
894 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
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:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

617 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