我自己用JS写的一个图片切换,请问我想用渐显的方式显示图片,该添加什么代码,求高手指点。
主要HTML代码如下:<body><divid="bg"><divid="pic"><ahref="#"><imgalt="red"title="red"src="red...
主要HTML代码如下:
<body>
<div id="bg">
<div id="pic">
<a href="#"><img alt="red" title="red" src="red.jpg" /></a>
<a href="#"><img alt="yellow" title="yellow" src="yellow.jpg" /></a>
<a href="#"><img alt="green" title="green" src="green.jpg" /></a>
<a href="#"><img alt="blue" title="blue" src="blue.jpg" /></a>
</div>
<div id="menu">
<ul>
<a href="javascript:void(0)"><li></li></a>
<a href="javascript:void(0)"><li></li></a>
<a href="javascript:void(0)"><li></li></a>
<a href="javascript:void(0)"><li></li></a>
</ul>
</div>
</div>
</body>
主要CSS如下:
#pic a{
display:none;
}
#pic a.visiable{
display:block;
/*filter:alpha(opacity=0);*/
}
主要JS代码如下:
var count = 0;
function init(){
var as1 = document.getElementById("pic").getElementsByTagName("a");
var as2 = document.getElementById("menu").getElementsByTagName("a");
for(j=0 ; j<as2.length ; j++){
as2[j].k =j;
as2[j].onmouseover = function(){
for(i=0 ; i<as2.length ; i++){
as1[i].className = '';
as2[i].className = '';
}
count = this.k;
as1[count].className = 'visiable';
as2[count].className = 'pshow';
}
}
show();
setInterval("show()",1500);
}
function show(){
var as1 = document.getElementById("pic").getElementsByTagName("a");
var as2 = document.getElementById("menu").getElementsByTagName("a");
if(count == as1.length){
as1[count-1].className = '';
as2[count-1].className = '';
count = 0;
}
if(count == 0){
as1[count].className = 'visiable';
as2[count].className = 'pshow';
count++;
}else{
as1[count-1].className = '';
as2[count-1].className = '';
as1[count].className = 'visiable';
as2[count].className = 'pshow';
count++;
}
}
window.onload = init; 展开
<body>
<div id="bg">
<div id="pic">
<a href="#"><img alt="red" title="red" src="red.jpg" /></a>
<a href="#"><img alt="yellow" title="yellow" src="yellow.jpg" /></a>
<a href="#"><img alt="green" title="green" src="green.jpg" /></a>
<a href="#"><img alt="blue" title="blue" src="blue.jpg" /></a>
</div>
<div id="menu">
<ul>
<a href="javascript:void(0)"><li></li></a>
<a href="javascript:void(0)"><li></li></a>
<a href="javascript:void(0)"><li></li></a>
<a href="javascript:void(0)"><li></li></a>
</ul>
</div>
</div>
</body>
主要CSS如下:
#pic a{
display:none;
}
#pic a.visiable{
display:block;
/*filter:alpha(opacity=0);*/
}
主要JS代码如下:
var count = 0;
function init(){
var as1 = document.getElementById("pic").getElementsByTagName("a");
var as2 = document.getElementById("menu").getElementsByTagName("a");
for(j=0 ; j<as2.length ; j++){
as2[j].k =j;
as2[j].onmouseover = function(){
for(i=0 ; i<as2.length ; i++){
as1[i].className = '';
as2[i].className = '';
}
count = this.k;
as1[count].className = 'visiable';
as2[count].className = 'pshow';
}
}
show();
setInterval("show()",1500);
}
function show(){
var as1 = document.getElementById("pic").getElementsByTagName("a");
var as2 = document.getElementById("menu").getElementsByTagName("a");
if(count == as1.length){
as1[count-1].className = '';
as2[count-1].className = '';
count = 0;
}
if(count == 0){
as1[count].className = 'visiable';
as2[count].className = 'pshow';
count++;
}else{
as1[count-1].className = '';
as2[count-1].className = '';
as1[count].className = 'visiable';
as2[count].className = 'pshow';
count++;
}
}
window.onload = init; 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询