<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
</head>
<style>
/*
change style attributes as needed - these were
simply for testing purposes
*/
#imgs {
position:absolute;
left: 6px;
top: 6px;
}
#txt {
position:absolute;
left: 256px;
top: 256px;
}
/* text contents go in here */
#containerCurrent {
border: 1px solid red;
color:red;
filter:alpha(opacity=100);
opacity:1;
font-size:25px;
position:absolute;
left: 6px;
top: 6px;
}
#containerNext {
border: 1px solid red;
color:red;
display: block;
filter:alpha(opacity=0);
opacity:0;
font-size:25px;
position:absolute;
left: 6px;
top: 6px;
}
</style>
<script type="text/javascript">
// utility overhead
var ua = navigator.userAgent;
var isIE = -1 != ua.indexOf('MSIE');
function get(eid) {
var e = document.getElementById( eid );
return e;
}
// contents to display - each image will reference
// the corresponding text by it index in the array
var contentsArray = [
'text1',
'text2'
];
// how long the entire fade process requires
var fadeRate = 1000; // msecs
// intializations
var currentContent = '';
var nextContent;
function fade(nIdx) {
// assign in-fading content by requested index
nextContent = contentsArray[nIdx];
// put next content in currently invisible container
get( 'containerNext' ).innerHTML = nextContent;
// local rate is 100th of overall rate of fade
var rate = fadeRate/100;
for (var i = 1; i < 101; i++) {
// queue fading commands
setTimeout('fadeOut(' + i + ')', rate*i);
setTimeout('fadeIn(' + i + ')', rate*i);
}
// queue final cleanup commands
setTimeout('finishFade(' + nIdx + ')', fadeRate);
}
function fadeIn(i) {
// increase opacity of in-fading, next content
var s = get( 'containerNext' ).style;
if (isIE) s.filter = 'alpha( opacity=' + i + ')';
else s.opacity = '' + .01*i;
}
function fadeOut(i) {
// decrease opacity of out-fading, next content
var s = get( 'containerCurrent' ).style;
if (isIE) s.filter = 'alpha( opacity=' + (100 - i) + ')';
else s.opacity = '' + .01*(100 - i);
}
function finishFade(nIdx) {
// reset current content to that which faded in
get('containerCurrent').innerHTML = nextContent;
var cs = get( 'containerCurrent' ).style;
var ns = get( 'containerNext' ).style;
// reset opacities to make current container again
// visible - contents of next no longer matter
if (isIE) {
cs.filter = 'alpha( opacity=100 )';
ns.filter = 'alpha( opacity=0 )';
}
else {
cs.opacity = '1';
ns.opacity = '0';
}
}
</script >
</head>
<body>
<div id="imgs">
<div onmouseover="fade(0)" /><a href="#">виж</a></div>
<div onmouseover="fade(1)" /><a href="#">виж</a></div>
</div>
<div id="txt">
<div id="containerCurrent"></div>
<div id="containerNext"></div>
</div>
</body>
</html>