kippie
Technical User
- Nov 8, 2001
- 158
In the HTML below I let one image scroll from left to right. Above it is a text. The idea is:
1. onMouseOver of the text and the image the scrolling stops
2. onMouseOut of the text and the image the scrolling continues where it was.
3. onMouseOver of the text the color of the text changes
4. onMouseOver of the image the color of the text changes also and in the same way as in 2.
5. onMouseOut of the text the color of the text changes back to the original color.
6. onMouseOut of the image the color of the text changes also back to the original color.
The final idea is to add more images and texts scrolling so that both texts and images are used as a sort of menu.
The problem is that onMouseOut of the image the scrolling jumps back, while onMouseOut of the text the scrolling continues nicely. I can't figure why the continuation of the scrolling goes wrong onMouseOut of the image while it works fine on the text. Could anyone help?
This is the HTML:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"<html xmlns="<head>
<title>Image Scroller</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<link href="layout2.css" rel="stylesheet" type="text/css">
<script language="javascript" src="sleight.js"></script>
<style type="text/css">
/*<![CDATA[*/
body {
background: #ffffff;
}
#middle {
position:absolute;
left: 0px;
top: 120px;
width: 1050px;
height: 350px;
overflow: hidden;
}
#container {
width: 3788px; /*total images width */
display: none;
position: absolute;
top: 0px;
border: solid 0px #6699cc;
}
.images {
float:left;
border:none;
}
.kop { color: #4c5ea1; font-weight: 700; font-size: 13px; font-family: Arial; text-align: left; width: 100% }
a.kop:link { color: #4c5ea1; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop:active { color: #4c5ea1; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop:visited { color: #4c5ea1; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop:hover { color: #ffae06; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop2:link { color: #ffae06; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop2:active { color: #ffae06; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop2:visited { color: #ffae06; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop2:hover { color: #4c5ea1; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
#wzw1{ position: absolute; top: 15px; left: 0px; width: 150px; height: 20px; visibility: visible }
#wzw2 { position: absolute; top:15px; left: 0px; width: 150px; height: 20px; visibility: hidden }
/*//]]>*/
</style>
<script language="javascript">
function hideLayers(sel) {
var eles = document.getElementsByTagName("div");
var all = (sel) ? 0 : 1;
if(all){
for(i=0;i<eles.length;i++) {
document.getElementById(eles.id).style.visibility="hidden";
}
}
else{
for(i=0;i<eles.length;i++) {
if(eles.id==sel) document.getElementById(eles.id).style.visibility="hidden";
}
}
}
function showLayer(sel) {
var eles = document.getElementsByTagName("div");
for(i=0;i<eles.length;i++) {
if (eles.id==sel) {
document.getElementById(sel).style.visibility="visible";
}
}
}
</script>
<script type="text/javascript">
//<![CDATA[
//* preload rollover
var roll = new Image()
roll.src = 'spiraalmetman3opt.jpg'
var x = 550;
var w = 3788; /*total images width */
var i = 0;
var speed = 5;
/*-----------------------------------------------------------------------------
Scroller functions
-----------------------------------------------------------------------------*/
function imageScroll() {
var Scontainer = document.getElementById("container").style;
Scontainer.display = "block";
Scontainer.left = (x - i) + "px";
i++;
if(i >(x + w)) {
i = 0;
}
scroller=setTimeout("imageScroll()",speed);
}
onload = imageScroll;
function stopScroll(el) {
clearTimeout(scroller);
}
/*-----------------------------------------------------------------------------
Image swap
- No 2nd arg = "swap back"
-----------------------------------------------------------------------------*/
function swap(img,src)
{
if(src){
img.oSrc = img.src;
img.src = src;
}
else
img.src = img.oSrc;
}
/*-----------------------------------------------------------------------------
Mouse events
-----------------------------------------------------------------------------*/
function img_mouseover(img, src)
{
stopScroll();
swap(img,src);
img.onmouseout = img_mouseout;
}
function img_mouseout()
{
imageScroll();
swap(this);
}
//]]>
</script>
</head>
<body>
<div id ="middle">
<div id = "container">
<table>
<tr>
<td height="30"><div id="wzw1"><img border="0" src = "dotwhite.gif" height="0" width="32">
<a href="" class="kop" target="_self" onmouseover = "stopScroll(this);return false" onmouseout = "img_mouseout()" alt = ""/>Wie zijn wij?</a>
</div>
<div id="wzw2"><img border="0" src = "dotwhite.gif" height="0" width="32">
<a href="" class="kop2" target="_self" onmouseover = "stopScroll(this);return false" onmouseout = "img_mouseout()" alt = ""/>Wie zijn wij?</a>
</div>
</td>
</tr>
<tr>
<td>
<a href=""><img class = "images" border="0" src = "intromanopschommelopt.jpg" onmouseover = "showLayer('wzw2'); hideLayers('wzw1'); stopScroll(this);return false;" onmouseout = "img_mouseout(); showLayer('wzw1'); hideLayers('wzw2');" alt = ""/></a>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>
1. onMouseOver of the text and the image the scrolling stops
2. onMouseOut of the text and the image the scrolling continues where it was.
3. onMouseOver of the text the color of the text changes
4. onMouseOver of the image the color of the text changes also and in the same way as in 2.
5. onMouseOut of the text the color of the text changes back to the original color.
6. onMouseOut of the image the color of the text changes also back to the original color.
The final idea is to add more images and texts scrolling so that both texts and images are used as a sort of menu.
The problem is that onMouseOut of the image the scrolling jumps back, while onMouseOut of the text the scrolling continues nicely. I can't figure why the continuation of the scrolling goes wrong onMouseOut of the image while it works fine on the text. Could anyone help?
This is the HTML:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"<html xmlns="<head>
<title>Image Scroller</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<link href="layout2.css" rel="stylesheet" type="text/css">
<script language="javascript" src="sleight.js"></script>
<style type="text/css">
/*<![CDATA[*/
body {
background: #ffffff;
}
#middle {
position:absolute;
left: 0px;
top: 120px;
width: 1050px;
height: 350px;
overflow: hidden;
}
#container {
width: 3788px; /*total images width */
display: none;
position: absolute;
top: 0px;
border: solid 0px #6699cc;
}
.images {
float:left;
border:none;
}
.kop { color: #4c5ea1; font-weight: 700; font-size: 13px; font-family: Arial; text-align: left; width: 100% }
a.kop:link { color: #4c5ea1; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop:active { color: #4c5ea1; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop:visited { color: #4c5ea1; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop:hover { color: #ffae06; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop2:link { color: #ffae06; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop2:active { color: #ffae06; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop2:visited { color: #ffae06; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
a.kop2:hover { color: #4c5ea1; font-weight: 700; font-size: 13px; font-family: Arial; text-decoration: none }
#wzw1{ position: absolute; top: 15px; left: 0px; width: 150px; height: 20px; visibility: visible }
#wzw2 { position: absolute; top:15px; left: 0px; width: 150px; height: 20px; visibility: hidden }
/*//]]>*/
</style>
<script language="javascript">
function hideLayers(sel) {
var eles = document.getElementsByTagName("div");
var all = (sel) ? 0 : 1;
if(all){
for(i=0;i<eles.length;i++) {
document.getElementById(eles.id).style.visibility="hidden";
}
}
else{
for(i=0;i<eles.length;i++) {
if(eles.id==sel) document.getElementById(eles.id).style.visibility="hidden";
}
}
}
function showLayer(sel) {
var eles = document.getElementsByTagName("div");
for(i=0;i<eles.length;i++) {
if (eles.id==sel) {
document.getElementById(sel).style.visibility="visible";
}
}
}
</script>
<script type="text/javascript">
//<![CDATA[
//* preload rollover
var roll = new Image()
roll.src = 'spiraalmetman3opt.jpg'
var x = 550;
var w = 3788; /*total images width */
var i = 0;
var speed = 5;
/*-----------------------------------------------------------------------------
Scroller functions
-----------------------------------------------------------------------------*/
function imageScroll() {
var Scontainer = document.getElementById("container").style;
Scontainer.display = "block";
Scontainer.left = (x - i) + "px";
i++;
if(i >(x + w)) {
i = 0;
}
scroller=setTimeout("imageScroll()",speed);
}
onload = imageScroll;
function stopScroll(el) {
clearTimeout(scroller);
}
/*-----------------------------------------------------------------------------
Image swap
- No 2nd arg = "swap back"
-----------------------------------------------------------------------------*/
function swap(img,src)
{
if(src){
img.oSrc = img.src;
img.src = src;
}
else
img.src = img.oSrc;
}
/*-----------------------------------------------------------------------------
Mouse events
-----------------------------------------------------------------------------*/
function img_mouseover(img, src)
{
stopScroll();
swap(img,src);
img.onmouseout = img_mouseout;
}
function img_mouseout()
{
imageScroll();
swap(this);
}
//]]>
</script>
</head>
<body>
<div id ="middle">
<div id = "container">
<table>
<tr>
<td height="30"><div id="wzw1"><img border="0" src = "dotwhite.gif" height="0" width="32">
<a href="" class="kop" target="_self" onmouseover = "stopScroll(this);return false" onmouseout = "img_mouseout()" alt = ""/>Wie zijn wij?</a>
</div>
<div id="wzw2"><img border="0" src = "dotwhite.gif" height="0" width="32">
<a href="" class="kop2" target="_self" onmouseover = "stopScroll(this);return false" onmouseout = "img_mouseout()" alt = ""/>Wie zijn wij?</a>
</div>
</td>
</tr>
<tr>
<td>
<a href=""><img class = "images" border="0" src = "intromanopschommelopt.jpg" onmouseover = "showLayer('wzw2'); hideLayers('wzw1'); stopScroll(this);return false;" onmouseout = "img_mouseout(); showLayer('wzw1'); hideLayers('wzw2');" alt = ""/></a>
</td>
</tr>
</table>
</div>
</div>
</body>
</html>