关于javascript图片轮换的问题,解决后马上结贴,等待中~~~~~

yangtzeu 2008-02-17 05:47:09
小弟遇到困惑,客户要求下面这个图片轮换效果要达到的要求是:
鼠标不点时,它自己变化切换效果(切换效果最好不要现在这样的,客户说太肉了?);
鼠标点击1-12个按扭时,快速切换(切换过程不要仍任何切换效果,即快速切换)
;
图片一定要12张,不能多不能少.
下面的代码直接保存.html可以运行 ,小弟js学的很浅显,请帮忙解决,谢谢!


<SCRIPT>
//Alpha:设置透明度
//Alpha(Opacity=?, FinishOpacity=?, Style=?, StartX=?, StartY=?, FinishX=?, FinishY=?)
//Opacity:透明度级别,范围是0-100,0代表完全透明,100代表完全不透明。
//FinishOpacity:设置渐变的透明效果时,用来指定结束时的透明度,范围也是0 到 100。
//Style:设置渐变透明的样式,值为0代表统一形状、1代表线形、2代表放射状、3代表长方形。
//StartX和StartY:代表渐变透明效果的开始X和Y坐标。
//FinishX和FinishY:代表渐变透明效果结束X和Y 的坐标。
var widths=340;
var heights=380;
var counts=12;
img1=new Image ();img1.src='http://www.hxxjhouse.com/2008/img/CYP512a.jpg';
img2=new Image ();img2.src='http://www.hxxjhouse.com/2008/img/CYP512b.jpg';
img3=new Image ();img3.src='http://www.hxxjhouse.com/2008/img/CYP512c.jpg';
img4=new Image ();img4.src='http://www.hxxjhouse.com/2008/img/CYP512d.jpg';
img5=new Image ();img5.src='http://www.hxxjhouse.com/2008/img/CYP512e.jpg';
img6=new Image ();img6.src='http://www.hxxjhouse.com/2008/img/CYP512f.jpg';
img7=new Image ();img7.src='http://www.hxxjhouse.com/2008/img/CYP512g.jpg';
img8=new Image ();img8.src='http://www.hxxjhouse.com/2008/img/CYP512h.jpg';
img9=new Image ();img9.src='http://www.hxxjhouse.com/2008/img/CYP512i.jpg';
img10=new Image ();img10.src='http://www.hxxjhouse.com/2008/img/CYP512j.jpg';
img11=new Image ();img11.src='http://www.hxxjhouse.com/2008/img/CYP512k.jpg';
img12=new Image ();img12.src='http://www.hxxjhouse.com/2008/img/CYP512l.jpg';

url1=new Image ();url1.src='http://www.hxxjhouse.com/2008/img/CYP512a.jpg';
url2=new Image ();url2.src='http://www.hxxjhouse.com/2008/img/CYP512b.jpg';
url3=new Image ();url3.src='http://www.hxxjhouse.com/2008/img/CYP512c.jpg';
url4=new Image ();url4.src='http://www.hxxjhouse.com/2008/img/CYP512d.jpg';
url5=new Image ();url5.src='http://www.hxxjhouse.com/2008/img/CYP512e.jpg';
url6=new Image ();url6.src='http://www.hxxjhouse.com/2008/img/CYP512f.jpg';
url7=new Image ();url1.src='http://www.hxxjhouse.com/2008/img/CYP512g.jpg';
url8=new Image ();url2.src='http://www.hxxjhouse.com/2008/img/CYP512h.jpg';
url9=new Image ();url3.src='http://www.hxxjhouse.com/2008/img/CYP512i.jpg';
url10=new Image ();url4.src='http://www.hxxjhouse.com/2008/img/CYP512j.jpg';
url11=new Image ();url5.src='http://www.hxxjhouse.com/2008/img/CYP512k.jpg';
url12=new Image ();url6.src='http://www.hxxjhouse.com/2008/img/CYP512l.jpg';

//天极
var nn=1;
var key=0;
function change_img()
{if(key==0){key=1;}
else if(document.all)
//下面去掉一个后只有切换效果,没有滤镜效果
{document.getElementById("pic").filters[0].Apply();document.getElementById("pic").filters[0].Play(duration=2);}
//{document.getElementById("pic").filters[0].Play(duration=2);}
eval('document.getElementById("pic").src=img'+nn+'.src');
eval('document.getElementById("url").href=url'+nn+'.src');
for (var i=1;i<=counts;i++){document.getElementById("xxjdjj"+i).className='axx';}
document.getElementById("xxjdjj"+nn).className='bxx';
nn++;if(nn>counts){nn=1;}
tt=setTimeout('change_img()',3000);}
function changeimg(n){nn=n;window.clearInterval(tt);change_img();}
document.write('<style>');
document.write('.axx{padding:1px 7px;border-left:#cccccc 1px solid;}');
document.write('a.axx:link,a.axx:visited{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#666;}');
document.write('a.axx:active,a.axx:hover{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#999;}');
document.write('.bxx{padding:1px 7px;border-left:#cccccc 1px solid;}');
document.write('a.bxx:link,a.bxx:visited{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#D34600;}');
document.write('a.bxx:active,a.bxx:hover{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#D34600;}');
document.write('</style>');
document.write('<div style="width:'+widths+'px;height:'+heights+'px;overflow:hidden;text-overflow:clip;">');
document.write('<div><span id="url"><img id="pic" style="border:0px;filter:progid:dximagetransform.microsoft.wipe(gradientsize=1.5,wipestyle=4, motion=forward)" width='+widths+' height='+heights+' /></span></div>');
document.write('<div style="filter:alpha(style=0,opacity=100,finishOpacity=80);background: #888888;width:100%-2px;text-align:right;top:-14px;position:relative;margin:1px;height:18px;padding:0px;margin:0px;border:0px;">');
for(var i=1;i<counts+1;i++){document.write('<a href="javascript:changeimg('+i+');" id="xxjdjj'+i+'" class="axx" target="_self">'+i+'</a>');}
document.write('</div></div>');
change_img();
</SCRIPT>
...全文
346 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangtzeu 2008-02-20
  • 打赏
  • 举报
回复
hzsasheng 的结果没有问题!
谢谢
stayalive 2008-02-18
  • 打赏
  • 举报
回复
原来:

function changeimg(n){nn=n;window.clearInterval(tt);change_img();}

修改为:

function changeimg(n){
nn=n;
eval('document.getElementById("pic").src=img'+nn+'.src');
eval('document.getElementById("url").href=url'+nn+'.src');
window.clearInterval(tt);
change_img();
}
haomas 2008-02-18
  • 打赏
  • 举报
回复
用JQuery吧 看着一堆杂乱的JS代码我就头晕
hzsasheng 2008-02-18
  • 打赏
  • 举报
回复
在楼主的基础上改了下,应该是符合楼主要求的,,楼主看看~~~


<SCRIPT>
//Alpha:设置透明度
//Alpha(Opacity=?, FinishOpacity=?, Style=?, StartX=?, StartY=?, FinishX=?, FinishY=?)
//Opacity:透明度级别,范围是0-100,0代表完全透明,100代表完全不透明。
//FinishOpacity:设置渐变的透明效果时,用来指定结束时的透明度,范围也是0 到 100。
//Style:设置渐变透明的样式,值为0代表统一形状、1代表线形、2代表放射状、3代表长方形。
//StartX和StartY:代表渐变透明效果的开始X和Y坐标。
//FinishX和FinishY:代表渐变透明效果结束X和Y 的坐标。
var widths=340;
var heights=380;
var counts=12;
img1=new Image ();img1.src='http://www.hxxjhouse.com/2008/img/CYP512a.jpg';
img2=new Image ();img2.src='http://www.hxxjhouse.com/2008/img/CYP512b.jpg';
img3=new Image ();img3.src='http://www.hxxjhouse.com/2008/img/CYP512c.jpg';
img4=new Image ();img4.src='http://www.hxxjhouse.com/2008/img/CYP512d.jpg';
img5=new Image ();img5.src='http://www.hxxjhouse.com/2008/img/CYP512e.jpg';
img6=new Image ();img6.src='http://www.hxxjhouse.com/2008/img/CYP512f.jpg';
img7=new Image ();img7.src='http://www.hxxjhouse.com/2008/img/CYP512g.jpg';
img8=new Image ();img8.src='http://www.hxxjhouse.com/2008/img/CYP512h.jpg';
img9=new Image ();img9.src='http://www.hxxjhouse.com/2008/img/CYP512i.jpg';
img10=new Image ();img10.src='http://www.hxxjhouse.com/2008/img/CYP512j.jpg';
img11=new Image ();img11.src='http://www.hxxjhouse.com/2008/img/CYP512k.jpg';
img12=new Image ();img12.src='http://www.hxxjhouse.com/2008/img/CYP512l.jpg';

url1=new Image ();url1.src='http://www.hxxjhouse.com/2008/img/CYP512a.jpg';
url2=new Image ();url2.src='http://www.hxxjhouse.com/2008/img/CYP512b.jpg';
url3=new Image ();url3.src='http://www.hxxjhouse.com/2008/img/CYP512c.jpg';
url4=new Image ();url4.src='http://www.hxxjhouse.com/2008/img/CYP512d.jpg';
url5=new Image ();url5.src='http://www.hxxjhouse.com/2008/img/CYP512e.jpg';
url6=new Image ();url6.src='http://www.hxxjhouse.com/2008/img/CYP512f.jpg';
url7=new Image ();url1.src='http://www.hxxjhouse.com/2008/img/CYP512g.jpg';
url8=new Image ();url2.src='http://www.hxxjhouse.com/2008/img/CYP512h.jpg';
url9=new Image ();url3.src='http://www.hxxjhouse.com/2008/img/CYP512i.jpg';
url10=new Image ();url4.src='http://www.hxxjhouse.com/2008/img/CYP512j.jpg';
url11=new Image ();url5.src='http://www.hxxjhouse.com/2008/img/CYP512k.jpg';
url12=new Image ();url6.src='http://www.hxxjhouse.com/2008/img/CYP512l.jpg';

//天极
var nn=1;
var key=0;
function change_img()
{if(key==0){key=1;}
else if(document.all)
//下面去掉一个后只有切换效果,没有滤镜效果
{
document.getElementById("pic").filters.revealTrans.Transition=23;
document.getElementById("pic").filters.revealTrans.apply();
document.getElementById("pic").filters.revealTrans.play();

//document.getElementById("pic").filters[0].Apply();
//document.getElementById("pic").filters[0].Play(duration=2);
}
//{document.getElementById("pic").filters[0].Play(duration=2);}
eval('document.getElementById("pic").src=img'+nn+'.src');
eval('document.getElementById("url").href=url'+nn+'.src');
for (var i=1;i <=counts;i++){document.getElementById("xxjdjj"+i).className='axx';}
document.getElementById("xxjdjj"+nn).className='bxx';
nn++;if(nn> counts){nn=1;}
tt=setTimeout('change_img()',3000);}

function changeimg(n){nn=n;window.clearInterval(tt);
eval('document.getElementById("pic").src=img'+nn+'.src');
eval('document.getElementById("url").href=url'+nn+'.src');
for (var i=1;i <=counts;i++){document.getElementById("xxjdjj"+i).className='axx';}
document.getElementById("xxjdjj"+nn).className='bxx';
nn++;if(nn> counts){nn=1;}
tt=setTimeout('change_img()',3000);
//change_img();
}
document.write(' <style> ');
document.write('.axx{padding:1px 7px;border-left:#cccccc 1px solid;}');
document.write('a.axx:link,a.axx:visited{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#666;}');
document.write('a.axx:active,a.axx:hover{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#999;}');
document.write('.bxx{padding:1px 7px;border-left:#cccccc 1px solid;}');
document.write('a.bxx:link,a.bxx:visited{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#D34600;}');
document.write('a.bxx:active,a.bxx:hover{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#D34600;}');
document.write(' </style> ');
document.write(' <div style="width:'+widths+'px;height:'+heights+'px;overflow:hidden;text-overflow:clip;"> ');
document.write(' <div> <span id="url"> <img id="pic" name="pic" style="FILTER: revealTrans(duration=1,transition=5);" width='+widths+' height='+heights+' /> </span> </div> ');
document.write(' <div style="filter:alpha(style=0,opacity=100,finishOpacity=80);background: #888888;width:100%-2px;text-align:right;top:-14px;position:relative;margin:1px;height:18px;padding:0px;margin:0px;border:0px;"> ');
for(var i=1;i <counts+1;i++){document.write(' <a href="javascript:changeimg('+i+');" id="xxjdjj'+i+'" class="axx" target="_self"> '+i+' </a> ');}
document.write(' </div> </div> ');
change_img();
</SCRIPT>
yangtzeu 2008-02-18
  • 打赏
  • 举报
回复
这是客户要求实现的,帮帮忙啊~~~~
回.到.未来 2008-02-18
  • 打赏
  • 举报
回复
hzsasheng的运行会报错啊!!
yjwang0621 2008-02-18
  • 打赏
  • 举报
回复
mark一下
一品梅 2008-02-17
  • 打赏
  • 举报
回复
自动切换好做,有些"花样"也就是动态画面渐变效果,似乎不太好做吧,期待高手...
xiaoniao_28 2008-02-17
  • 打赏
  • 举报
回复
呵呵 CSDN主页上就是啊 LZ 去看看原代码了
自动切换主要是 setInterval()
清除自动  clearInterval()
MarcuseXiao 2008-02-17
  • 打赏
  • 举报
回复
关注
hui717 2008-02-17
  • 打赏
  • 举报
回复
关注,学习一下
yangtzeu 2008-02-17
  • 打赏
  • 举报
回复
谢谢你,但不是我想要的结果

结果要这样的效果:
鼠标不点时图片能自动变换切换(有点花样)

鼠标点击时:快速切换(没有任何花样)

两种要不一样的.
winner2050 2008-02-17
  • 打赏
  • 举报
回复
<SCRIPT>
//Alpha:设置透明度
//Alpha(Opacity=?, FinishOpacity=?, Style=?, StartX=?, StartY=?, FinishX=?, FinishY=?)
//Opacity:透明度级别,范围是0-100,0代表完全透明,100代表完全不透明。
//FinishOpacity:设置渐变的透明效果时,用来指定结束时的透明度,范围也是0 到 100。
//Style:设置渐变透明的样式,值为0代表统一形状、1代表线形、2代表放射状、3代表长方形。
//StartX和StartY:代表渐变透明效果的开始X和Y坐标。
//FinishX和FinishY:代表渐变透明效果结束X和Y 的坐标。
var widths=340;
var heights=380;
var counts=12;
img1=new Image ();img1.src='http://www.hxxjhouse.com/2008/img/CYP512a.jpg';
img2=new Image ();img2.src='http://www.hxxjhouse.com/2008/img/CYP512b.jpg';
img3=new Image ();img3.src='http://www.hxxjhouse.com/2008/img/CYP512c.jpg';
img4=new Image ();img4.src='http://www.hxxjhouse.com/2008/img/CYP512d.jpg';
img5=new Image ();img5.src='http://www.hxxjhouse.com/2008/img/CYP512e.jpg';
img6=new Image ();img6.src='http://www.hxxjhouse.com/2008/img/CYP512f.jpg';
img7=new Image ();img7.src='http://www.hxxjhouse.com/2008/img/CYP512g.jpg';
img8=new Image ();img8.src='http://www.hxxjhouse.com/2008/img/CYP512h.jpg';
img9=new Image ();img9.src='http://www.hxxjhouse.com/2008/img/CYP512i.jpg';
img10=new Image ();img10.src='http://www.hxxjhouse.com/2008/img/CYP512j.jpg';
img11=new Image ();img11.src='http://www.hxxjhouse.com/2008/img/CYP512k.jpg';
img12=new Image ();img12.src='http://www.hxxjhouse.com/2008/img/CYP512l.jpg';

url1=new Image ();url1.src='http://www.hxxjhouse.com/2008/img/CYP512a.jpg';
url2=new Image ();url2.src='http://www.hxxjhouse.com/2008/img/CYP512b.jpg';
url3=new Image ();url3.src='http://www.hxxjhouse.com/2008/img/CYP512c.jpg';
url4=new Image ();url4.src='http://www.hxxjhouse.com/2008/img/CYP512d.jpg';
url5=new Image ();url5.src='http://www.hxxjhouse.com/2008/img/CYP512e.jpg';
url6=new Image ();url6.src='http://www.hxxjhouse.com/2008/img/CYP512f.jpg';
url7=new Image ();url1.src='http://www.hxxjhouse.com/2008/img/CYP512g.jpg';
url8=new Image ();url2.src='http://www.hxxjhouse.com/2008/img/CYP512h.jpg';
url9=new Image ();url3.src='http://www.hxxjhouse.com/2008/img/CYP512i.jpg';
url10=new Image ();url4.src='http://www.hxxjhouse.com/2008/img/CYP512j.jpg';
url11=new Image ();url5.src='http://www.hxxjhouse.com/2008/img/CYP512k.jpg';
url12=new Image ();url6.src='http://www.hxxjhouse.com/2008/img/CYP512l.jpg';

//天极
var nn=1;
var key=0;
function change_img()
{if(key==0){key=1;}
else if(document.all)
//下面去掉一个后只有切换效果,没有滤镜效果
//{document.getElementById("pic").filters[0].Apply();document.getElementById("pic").filters[0].Play(duration=2);}
//{document.getElementById("pic").filters[0].Play(duration=2);}
eval('document.getElementById("pic").src=img'+nn+'.src');
eval('document.getElementById("url").href=url'+nn+'.src');
for (var i=1;i <=counts;i++){document.getElementById("xxjdjj"+i).className='axx';}
document.getElementById("xxjdjj"+nn).className='bxx';
nn++;if(nn> counts){nn=1;}
tt=setTimeout('change_img()',3000);}
function changeimg(n){nn=n;window.clearInterval(tt);change_img();}
document.write(' <style> ');
document.write('.axx{padding:1px 7px;border-left:#cccccc 1px solid;}');
document.write('a.axx:link,a.axx:visited{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#666;}');
document.write('a.axx:active,a.axx:hover{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#999;}');
document.write('.bxx{padding:1px 7px;border-left:#cccccc 1px solid;}');
document.write('a.bxx:link,a.bxx:visited{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#D34600;}');
document.write('a.bxx:active,a.bxx:hover{text-decoration:none;color:#fff;line-height:18px;font:9px sans-serif;background-color:#D34600;}');
document.write(' </style> ');
document.write(' <div style="width:'+widths+'px;height:'+heights+'px;overflow:hidden;text-overflow:clip;"> ');
document.write(' <div> <span id="url"> <img id="pic" style="border:0px;filter:progid:dximagetransform.microsoft.wipe(gradientsize=1.5,wipestyle=4, motion=forward)" width='+widths+' height='+heights+' /> </span> </div> ');

document.write(' <div style="filter:alpha(style=0,opacity=100,finishOpacity=80);background: #888888;width:100%-2px;text-align:right;top:-14px;position:relative;margin:1px;height:18px;padding:0px;margin:0px;border:0px;"> ');
for(var i=1;i <counts+1;i++){document.write(' <a href="javascript:changeimg('+i+');" id="xxjdjj'+i+'" class="axx" target="_self"> '+i+' </a> ');}
document.write(' </div> </div> ');
change_img();
</SCRIPT>

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧