div+css+javascript图片切换(淡入浅出效果)
2011-01-27 15:08
423 查看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>div+css+js图片切换(淡入浅出效果)</title>
</head>
<body>
<STYLE type=text/css>
#f_div {
margin: 0px auto; overflow: hidden; width: 240px; height: 210px;
}
#f_imgdiv {
overflow: hidden; width: 100%; height: 210px;
}
#f_img {
border-right: 0px; border-top: 0px; filter: progid:DXImageTransform.Microsoft.Fade(Overlap=1.00); border-left: 0px; border-bottom: 0px;
}
#f_infodiv {
width: 100%; position: relative; top: -18px;
}
#f_buttondiv {
overflow: hidden; width: 100%; height: 17px; text-align: left;
}
#f_buttondiv div {
background: #fff; float: right; width: 1px; height: 17px;
}
#f_buttondiv .bg {
background: #fff; filter: Alpha(Opacity=40); float: right; width: 17px; height: 17px;
}
#f_buttondiv a {
display: block; font-size: 10px; float: right; overflow: hidden; width: 17px; color: #fff; line-height: 10px; padding-top: 5px; font-family: Arial, Helvetica, sans-serif; position: absolute; height: 13px; text-align: center; text-decoration: none;
}
#f_buttondiv a:link {
color: #000;
}
#f_buttondiv a:visited {
color: #000;
}
#f_buttondiv a:active {
color: #000;
}
#f_buttondiv a:hover {
background:blue; color: #fff;
}
#f_buttondiv a.on:link {
background:blue; color: #fff;
}
#f_buttondiv a.on:visited {
background:blue; color: #fff;
}
#f_buttondiv a.on:active {
background:blue; color: #fff;
}
#f_buttondiv a.on:hover {
background:blue; color: #fff;
}
#f_buttondiv a.on:hover {
background:blue;
}
//数字按钮的链接颜色
</STYLE>
<div id=f_div><!--图片区域-->
<div id=f_imgdiv></div>
<div id=f_infodiv><!--数字按钮区域-->
<div id=f_buttondiv></div></div></div>
<SCRIPT>
//可修改区域
var imgwidth=240;//宽
var imgheight=210;//高
var _timeOut_=5000;//过渡时间
var show_text= true; //是否显示焦点文字
var timeOut=_timeOut_;
var timeOut2=_timeOut_/2;//onmouseout img后需要切换的时间
var now=0; //第一张图
var target="_blank"; //打开方式
var button_on ='on'; //当前焦点对应按钮的样式名
var button_off ='';//非当前焦点对应按钮的样式名
//不可修改区域
var imgUrl = new Array();
var imgText = new Array();
var imgLink = new Array();
var imgAlt= new Array();
//var menuList = new Array();//菜单menu
var ver=2; //兼容浏览器版本 默认2 为非ie
var firstTime=true;
var n=-1;
imgUrl[++n]='images/01.jpg';
imgText
='<a href="http://#" target="_blank" class=linkblack>图片名称1</a>';
imgLink
='http://#';
imgAlt
='图片名称1';
imgUrl[++n]='images/02.jpg';
imgText
='<a href="http://#" target="_blank" class=linkblack>图片名称2</a>';
imgLink
='http://idc.yovole.com';
imgAlt
='图片名称2';
imgUrl[++n]='images/03.jpg';
imgText
='<a href="http://#" target="_blank" class=linkblack>图片名称3</a>';
imgLink
='http://#';
imgAlt
='图片名称3';
var count=0;
for (i=0;i<imgUrl.length;i++) {
if((imgUrl[i]!="") && (imgText[i]!="")&& (imgLink[i]!="")&& (imgAlt[i]!="")) {
count++;
} else {
break;
}
}
function p$(string){
document.write(string);
}
function $(id){
return document.getElementById(id);
}
//固定图片size
p$("<style> #f_img { width:"+imgwidth+"px;height:"+imgheight+"px;</style>");
function change(){
if (ver==1){
with($('f_img').filters[0]){
Transition=1;
apply();
play();
}
}
if (firstTime){ firstTime=false;timeOut=_timeOut_/1000;}
else{
$('f_img').src=imgUrl[now];
$('f_img').alt=imgAlt[now];
$('f_imgLink').href=imgLink[now];
for (var i=0;i<count;i++) {
$('b'+i).className="button";
//$('f_menu'+i).className="";
}
$('b'+now).className="on";
//$('f_menu'+now).className="on";
now=(now>=imgUrl.length-1)?0:now+1;
timeOut=_timeOut_;
}
theTimer=setTimeout("change()", timeOut);
}
function b_change(num){
window.clearInterval(theTimer);
now=num;
firstTime=false;
change();
}
//draw 渐变line (即css:f_line)
function draw_line(){
var div = document.createElement("div");
div.id = 'f_line';
$('f_infodiv').insertBefore(div,$('f_infodiv').childNodes.item(0));
}
//表现层 start
//图片
var a = document.createElement("a");
a.id="f_imgLink";
a.target=target;
a.href=imgLink[now];
$('f_imgdiv').appendChild(a);
var img = document.createElement("img");
img.id="f_img";
img.width=imgwidth;
img.height=imgheight;
img.src=imgUrl[now];
img.alt=imgAlt[now];
a.appendChild(img);
//数字按钮
for (var i=count-1;i>=0;i--){
var div_bg = document.createElement("div");
div_bg.id = 'div_bg'+i;
div_bg.className='bg';
$('f_buttondiv').appendChild(div_bg);
var a = document.createElement("a");
a.id = 'b'+i;
a.className = (i==now+1)?"button_on":"button_off";
a.title=imgAlt[i];
a.innerHTML=i+1;
a.href='javascript:b_change('+i+')';
$('div_bg'+i).appendChild(a);
var div= document.createElement("div");
$('f_buttondiv').appendChild(div);
}
//表现层 end
$('f_img').onmouseover=function(){window.clearInterval(theTimer);}
$('f_img').onmouseout=function(){theTimer=setTimeout("change()", timeOut2);}
try{ //滤镜版本
new ActiveXObject("DXImageTransform.Microsoft.Fade");
$('f_img').filters[0].play();
ver=1;
draw_line();
}
catch (e){ver=2;}
var theTimer = setTimeout("change()", _timeOut_/1000);
</SCRIPT>
</body>
</html>
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>div+css+js图片切换(淡入浅出效果)</title>
</head>
<body>
<STYLE type=text/css>
#f_div {
margin: 0px auto; overflow: hidden; width: 240px; height: 210px;
}
#f_imgdiv {
overflow: hidden; width: 100%; height: 210px;
}
#f_img {
border-right: 0px; border-top: 0px; filter: progid:DXImageTransform.Microsoft.Fade(Overlap=1.00); border-left: 0px; border-bottom: 0px;
}
#f_infodiv {
width: 100%; position: relative; top: -18px;
}
#f_buttondiv {
overflow: hidden; width: 100%; height: 17px; text-align: left;
}
#f_buttondiv div {
background: #fff; float: right; width: 1px; height: 17px;
}
#f_buttondiv .bg {
background: #fff; filter: Alpha(Opacity=40); float: right; width: 17px; height: 17px;
}
#f_buttondiv a {
display: block; font-size: 10px; float: right; overflow: hidden; width: 17px; color: #fff; line-height: 10px; padding-top: 5px; font-family: Arial, Helvetica, sans-serif; position: absolute; height: 13px; text-align: center; text-decoration: none;
}
#f_buttondiv a:link {
color: #000;
}
#f_buttondiv a:visited {
color: #000;
}
#f_buttondiv a:active {
color: #000;
}
#f_buttondiv a:hover {
background:blue; color: #fff;
}
#f_buttondiv a.on:link {
background:blue; color: #fff;
}
#f_buttondiv a.on:visited {
background:blue; color: #fff;
}
#f_buttondiv a.on:active {
background:blue; color: #fff;
}
#f_buttondiv a.on:hover {
background:blue; color: #fff;
}
#f_buttondiv a.on:hover {
background:blue;
}
//数字按钮的链接颜色
</STYLE>
<div id=f_div><!--图片区域-->
<div id=f_imgdiv></div>
<div id=f_infodiv><!--数字按钮区域-->
<div id=f_buttondiv></div></div></div>
<SCRIPT>
//可修改区域
var imgwidth=240;//宽
var imgheight=210;//高
var _timeOut_=5000;//过渡时间
var show_text= true; //是否显示焦点文字
var timeOut=_timeOut_;
var timeOut2=_timeOut_/2;//onmouseout img后需要切换的时间
var now=0; //第一张图
var target="_blank"; //打开方式
var button_on ='on'; //当前焦点对应按钮的样式名
var button_off ='';//非当前焦点对应按钮的样式名
//不可修改区域
var imgUrl = new Array();
var imgText = new Array();
var imgLink = new Array();
var imgAlt= new Array();
//var menuList = new Array();//菜单menu
var ver=2; //兼容浏览器版本 默认2 为非ie
var firstTime=true;
var n=-1;
imgUrl[++n]='images/01.jpg';
imgText
='<a href="http://#" target="_blank" class=linkblack>图片名称1</a>';
imgLink
='http://#';
imgAlt
='图片名称1';
imgUrl[++n]='images/02.jpg';
imgText
='<a href="http://#" target="_blank" class=linkblack>图片名称2</a>';
imgLink
='http://idc.yovole.com';
imgAlt
='图片名称2';
imgUrl[++n]='images/03.jpg';
imgText
='<a href="http://#" target="_blank" class=linkblack>图片名称3</a>';
imgLink
='http://#';
imgAlt
='图片名称3';
var count=0;
for (i=0;i<imgUrl.length;i++) {
if((imgUrl[i]!="") && (imgText[i]!="")&& (imgLink[i]!="")&& (imgAlt[i]!="")) {
count++;
} else {
break;
}
}
function p$(string){
document.write(string);
}
function $(id){
return document.getElementById(id);
}
//固定图片size
p$("<style> #f_img { width:"+imgwidth+"px;height:"+imgheight+"px;</style>");
function change(){
if (ver==1){
with($('f_img').filters[0]){
Transition=1;
apply();
play();
}
}
if (firstTime){ firstTime=false;timeOut=_timeOut_/1000;}
else{
$('f_img').src=imgUrl[now];
$('f_img').alt=imgAlt[now];
$('f_imgLink').href=imgLink[now];
for (var i=0;i<count;i++) {
$('b'+i).className="button";
//$('f_menu'+i).className="";
}
$('b'+now).className="on";
//$('f_menu'+now).className="on";
now=(now>=imgUrl.length-1)?0:now+1;
timeOut=_timeOut_;
}
theTimer=setTimeout("change()", timeOut);
}
function b_change(num){
window.clearInterval(theTimer);
now=num;
firstTime=false;
change();
}
//draw 渐变line (即css:f_line)
function draw_line(){
var div = document.createElement("div");
div.id = 'f_line';
$('f_infodiv').insertBefore(div,$('f_infodiv').childNodes.item(0));
}
//表现层 start
//图片
var a = document.createElement("a");
a.id="f_imgLink";
a.target=target;
a.href=imgLink[now];
$('f_imgdiv').appendChild(a);
var img = document.createElement("img");
img.id="f_img";
img.width=imgwidth;
img.height=imgheight;
img.src=imgUrl[now];
img.alt=imgAlt[now];
a.appendChild(img);
//数字按钮
for (var i=count-1;i>=0;i--){
var div_bg = document.createElement("div");
div_bg.id = 'div_bg'+i;
div_bg.className='bg';
$('f_buttondiv').appendChild(div_bg);
var a = document.createElement("a");
a.id = 'b'+i;
a.className = (i==now+1)?"button_on":"button_off";
a.title=imgAlt[i];
a.innerHTML=i+1;
a.href='javascript:b_change('+i+')';
$('div_bg'+i).appendChild(a);
var div= document.createElement("div");
$('f_buttondiv').appendChild(div);
}
//表现层 end
$('f_img').onmouseover=function(){window.clearInterval(theTimer);}
$('f_img').onmouseout=function(){theTimer=setTimeout("change()", timeOut2);}
try{ //滤镜版本
new ActiveXObject("DXImageTransform.Microsoft.Fade");
$('f_img').filters[0].play();
ver=1;
draw_line();
}
catch (e){ver=2;}
var theTimer = setTimeout("change()", _timeOut_/1000);
</SCRIPT>
</body>
</html>
相关文章推荐
- HTML+css+JavaScript 实例应用 图片旋转切换效果
- css图片切换效果分析+翻译整理
- 基于javascript实现图片切换效果
- jquery+css实现动感的图片切换效果
- 绝对纯CSS和JS的图片切换(轮换)效果!没有用FLASH
- CSS+JavaScript打造鼠标悬停图片渐显效果!
- JS + CSS 图片切换效果
- JavaScript基础 显示/隐藏效果 点击图片,DIV显示,图片更换,点击更换后的图片,DIV隐藏
- javascript实现div+css切换
- JavaScript 图片滑动切换效果
- JavaScript图片水平淡入淡出切换效果代码
- 用javascript和CSS来做模拟网页中图片的圆角效果 [转]
- 1.纯css实现鼠标移动图片切换的效果
- css基础之 图片瀑布流布局:用CSS+DIV等宽格子堆砌瀑布流效果 (一)
- JavaScript 图片滑动切换效果
- 非常不错的 子鼠 滑动图片效果 Javascript+CSS
- js+div实现文字滚动和图片切换效果代码
- CSS+jQuery/JavaScript图片切换播放
- JS + CSS 图片切换效果
- 图片切换效果beta3纯CSS构造