CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Web 开发 >  JavaScript

100分求滚动新闻图片的代码

楼主weiloon()2006-07-01 11:23:26 在 Web 开发 / JavaScript 提问

有谁知道象http://www.csdn.net/首页面上的滚动新闻图片的做法.请不吝赐教,谢谢!  
  问题点数:100、回复次数:5Top

1 楼elevenkey(飞)回复于 2006-07-01 12:02:39 得分 30

<div   style="width:589px;   height:25px;   position:absolute;float:right;">  
  <table   width="100"   border="0"   cellpadding="0"   cellspacing="1"   bgcolor="#ffffff"   align="right">  
      <tr>  
  <td   style="cursor:hand;"   width="25"   onmouseover="this.bgColor='#efefef';nextAd();"     onmouseout="this.bgColor='#FFCC33';"   height="14"   align="center"   bgcolor="#FFCC33"   class="black112">1</td>  
  <td   style="cursor:hand;"   width="25"   onmouseover="this.bgColor='#efefef';nextAd();"     onmouseout="this.bgColor='#6699FF';"   height="14"   align="center"   bgcolor="#6699FF"   class="black112">2</td>  
  <td   style="cursor:hand;"   width="25"   onmouseover="this.bgColor='#efefef';nextAd();"     onmouseout="this.bgColor='#99CC00';"   height="14"   align="center"   bgcolor="#99CC00"   class="black112">3</td>  
  <td   style="cursor:hand;"   width="25"   onmouseover="this.bgColor='#efefef';nextAd();"     onmouseout="this.bgColor='#CC9999';"   height="14"   align="center"   bgcolor="#CC9999"   class="black112">4</td>  
      </tr>  
  </table>  
   
  </div>  
  <div   style="width:589px;height:171px;   position:fixed;"><a   href="javascript:goUrl()"><img   style="FILTER:   progid:DXImageTransform.Microsoft.RevealTrans   (duration=1,transition=3);border-color:#000000;color:#000000;margin-bottom:0px"   src="javascript:nextAd()"   height=171   width=589   border=0   name=imgInit></a></div>  
   
  <script   language=JavaScript>  
  function   MM_preloadImages()   {   //v3.0  
      var   d=document;   if(d.images){   if(!d.MM_p)   d.MM_p=new   Array();  
  var   i,j=d.MM_p.length,a=MM_preloadImages.arguments;   for(i=0;   i<a.length;   i++)  
  if   (a[i].indexOf("#")!=0){   d.MM_p[j]=new   Image;   d.MM_p[j++].src=a[i];}}  
  }  
   
  var   imgUrl=new   Array();  
  var   imgLink=new   Array();  
  var   adNum=0;  
  imgUrl[1]="images/pop1.png";  
  imgLink[1]="#";  
  imgUrl[2]="images/pop11.png";  
  imgLink[2]="#";  
  imgUrl[3]="images/pop111.png";  
  imgLink[3]="#";  
   
  var   imgPre=new   Array();  
  var   j=0;  
  for   (i=1;i<=3;i++)   {  
  if(   (imgUrl[i]!="")   &&   (imgLink[i]!="")   )   {  
  j++;  
  }   else   {  
  break;  
  }  
  }  
   
  function   playTran(){  
  if   (document.all){  
  document.imgInit.filters[0].play();  
  }  
  }  
   
  function   nextAd(){  
  if(adNum<j)adNum++   ;  
  else   adNum=1;  
   
  if   (document.all){  
  document.imgInit.filters[0].Transition=26;  
  document.imgInit.filters[0].apply();  
  }  
  document.images.imgInit.src=imgUrl[adNum];  
  playTran();  
  //theTimer=setTimeout("nextAd()",   6000);  
  }  
   
   
  function   goUrl(){  
  jumpUrl=imgLink[adNum];  
  jumpTarget='_blank';  
  if   (jumpUrl   !=   ''){  
  if   (jumpTarget   !=   '')    
  window.open(jumpUrl,jumpTarget);  
  else  
  location.href=jumpUrl;  
  }  
  }  
  </script>Top

2 楼elevenkey(飞)回复于 2006-07-01 12:03:18 得分 10

不好意思,代码有点乱。Top

3 楼theforever(碧海情天)回复于 2006-07-01 13:14:34 得分 5

markTop

4 楼goodstuday(路漫漫)回复于 2006-07-01 13:19:47 得分 25

转自CSDN网友  
  --------------------  
  <style>  
  #g_div{text-align:right;overflow:hidden}  
  .b{width:24px;   height:16px;   background:#737373;   font-size:14px;   font-weight:bold;   color:#fff;   text-decoration:none;margin-left:1px}  
  .b:hover{width:24px;   height:16px;   background:#780001;   font-size:14px;   font-weight:bold;   color:#fff;   text-decoration:none;margin-left:1px}  
  .bhover{width:24px;   height:16px;   background:#780001;   font-size:14px;   font-weight:bold;   color:#fff;   text-decoration:none;margin-left:1px}  
  </style>  
   
  <div   id="g_div"   style="width:270px;height:252px">  
  <a   href="#"   target=_blank><img   id="g_img"   style="FILTER:revealTrans(duration=1,transition=23);width:266px;height:220px;border:1px   green   solid"   src="http://zi.csdn.net/xian.gif"></a>  
  <a   href="http://www.baidu.com/"   for="http://zi.csdn.net/xian.gif"     target="_blank">1.CSDN程序员</a>  
  <a   href="http://www.126.com/"   for="http://zi.csdn.net/microsoft280_187.jpg"     target="_blank">2.CSDN程序员</a>  
  <a   href="http://mp3.baidu.com/"     for="http://zi.csdn.net/live.gif"       target="_blank">3.CSDN程序员</a>  
  <a   href="http://post.baidu.com/"   for="http://zi.csdn.net/new-mba.gif"     target="_blank">4.CSDN程序员</a>  
  <a   href="http://top.baidu.com/"   for="http://zi.csdn.net/book.jpg"     target="_blank">5.CSDN程序员</a>  
  </div>  
  <script   language="JavaScript">  
  function   f(){  
  var   g_sec=3                     //几秒后切换图片  
  var   g_items=new   Array()  
  var   g_div=document.getElementById("g_div")    
  var   g_img=document.getElementById("g_img")    
  var   g_imglink=g_img.parentElement  
  var   arr=g_div.getElementsByTagName("A")  
  var   arr_length=arr.length  
  var   g_index=1  
   
  var   show_img=function(n){      
        if   (/\d+/.test(n)){  
  var   prev=g_index+1  
  g_index=n-1  
        }else{        
  var   prev=(g_index>arr.length)?(arr_length-1):g_index+1  
  g_index=(g_index<arr_length-2)?(++g_index):0  
        }    
        if   (document.all){  
        g_img.filters.revealTrans.Transition=23;  
      g_img.filters.revealTrans.apply();  
      g_img.filters.revealTrans.play();  
          }  
    arr[prev].className="b"      
    arr[g_index+1].className="bhover"  
    g_img.src=g_items[g_index].img.src  
    g_img.title=g_items[g_index].txt  
    g_imglink.href=g_items[g_index].url      
    g_imglink.target=g_items[g_index].target  
       
  }  
   
  for(var   i=1;i<arr_length;i++){  
  g_items.push({txt:arr[i].innerHTML,  
  url:arr[i].href,  
  target:arr[i].target,  
  img:(function(){var   o=new   Image;o.src=arr[i].getAttribute("for");return   o})()})    
  arr[i].title=arr[i].innerHTML  
  arr[i].innerHTML=[i,"&nbsp;"].join("")  
  arr[i].className="b"  
  arr[i].onclick=function(){  
  event.returnValue=false;  
  show_img(event.srcElement.innerText)  
  }  
  }  
  show_img(1)  
  var   t=window.setInterval(show_img,g_sec*1000)    
  g_img.onmouseover=function(){window.clearInterval(t)}  
  g_img.onmouseout=function(){t=window.setInterval(show_img,g_sec*1000)}      
  }  
   
  window.attachEvent("onload",f)    
  </script>  
  Top

5 楼zhuangyan2004(庄严)回复于 2006-07-01 13:48:24 得分 30

我的是jsp版的,从数据库里取的值  
  ====================  
  <TABLE   cellSpacing=0   cellPadding=0   width="100%"   align=center   border=0>  
      <TBODY>  
      <TR   vAlign=top>  
          <TD   vAlign=top   align=middle>  
  <!--begin:图片轮换开始-->  
              <SCRIPT   language=JavaScript>  
  var   imgUrl=new   Array();  
  var   imgLink=new   Array();  
  var   imgTz=new   Array();  
  var   buttonShow=1;  
  var   buttonPos=1;  
  var   buttonX;  
  var   buttonY;  
  var   bakularCode=""  
  var   adNum=0;  
  var   dakularCode="";  
  <%  
  List   list=new   ArrayList();  
  news   news=new   news();  
  newsBean   nBean=new   newsBean();  
  String   strSql="select   *   from   news   where   news_catalog>=1101   and     news_catalog<=1107   and   news_image<>''   and   news_image<>'null'   order   by   index_n   desc,news_id   desc   limit   5";  
  list=news.getNewsList(strSql);  
  Iterator   i=list.iterator();  
  int   cnt=1;  
  while(i.hasNext())  
  {  
  nBean=(newsBean)i.next();  
  %>  
  imgUrl[<%=cnt%>]="/news/images/<%=nBean.getNews_image()%>";  
  imgLink[<%=cnt%>]="/jdjs/jdview.jsp?id=<%=nBean.getNews_id()%>";  
  imgTz[<%=cnt%>]="<%=nBean.getNews_title()%>";  
  <%  
  cnt++;  
  }  
  %>  
  var   imgPre=new   Array();  
  for   (i=1;i<8;i++)  
  {  
  imgPre[i]=new   Image();  
          imgPre[i].src=imgUrl[i];  
    }  
  function   setTransition()  
  {  
  if   (document.all)  
  {  
  imgUrlrotator.filters.revealTrans.Transition=23;//Math.floor(Math.random()*23)  
          imgUrlrotator.filters.revealTrans.apply();  
  }  
  }  
  function   playTransition()  
  {  
    if   (document.all)  
    imgUrlrotator.filters.revealTrans.play()  
  }  
  function   nextAd(toNum)  
  {  
  if(adNum<imgUrl.length-1)  
  adNum++   ;  
  else  
  adNum=1;  
          if(toNum!=null)   adNum=toNum;  
          setTransition();  
  document.images.imgUrlrotator.src=imgUrl[adNum];  
  document.getElementById('linktext').innerHTML=imgTz[adNum];  
  document.images.imgUrlrotator.alt='推荐景点:'+imgTz[adNum];  
  document.getElementById('linktext').innerHTML="<a   href="+imgLink[adNum]+"   target=_blank   class=px14-lh20><font   style='font-size:14px'>"+imgTz[adNum]+"</font></a>";    
  playTransition();  
  checkButton();  
  if(toNum!=null)  
    {toNum=null;theTimer=setTimeout("nextAd()",   7000);}  
  else  
  {theTimer=setTimeout("nextAd()",   7000);}  
  }  
  function   jump2url()  
  {  
  jumpUrl=imgLink[adNum];jumpTarget='_blank';  
  if   (jumpUrl   !=   '')  
  { if   (jumpTarget   !=   '')  
          window.open(jumpUrl,jumpTarget);  
  else   location.href=jumpUrl;  
          }  
  }  
  function   displayStatusMsg()  
  {  
  status=imgLink[adNum];  
          document.returnValue   =   true;  
    }  
  function   checkButton()  
  {  
  for(i=1;i<=imgUrl.length-1;i++)  
  {if(i==adNum)  
  //document.getElementById('bt'+i).style.backgroundColor='#00FF00';  
  eval("bt"+i+".style.backgroundColor='#9B0000';bt"+i+".style.color='#FFFFFF';");  
  else  
  eval("bt"+i+".style.backgroundColor='#CCCCCC';bt"+i+".style.color='#000000';");  
  }  
  }  
  function   dakularButtons()  
  {  
  if(buttonShow==1)  
  {  
  switch(buttonPos)  
  {  
  case   1:{buttonX=300+20-imgUrl.length*20;buttonY=16;break;}  
  case   2:{buttonX=300+20-imgUrl.length*20;buttonY=125;break;}  
  case   3:{buttonX=imgUrl.length*20-100;buttonY=16;break;}  
  case   4:{buttonX=imgUrl.length*20-100;buttonY=125;break;}  
  default:{buttonX=300+20-imgUrl.length*20;buttonY=16;break;}  
  }  
  for(i=1;i<=imgUrl.length-1;i++)  
  {  
  dakularCode=dakularCode+"<div   id='bt"+i+"'   style='display:inline;   height=14px;   width:20px;   border:1px   solid   #000000;   background-color:#f7f7f7;   color:#000000;   font-size:12px;   line-height:14px;'   align='center'   onMouseOver=this.style.backgroundColor='#FFFFFF';this.style.color='#000000';this.style.cursor='hand'   onMouseOut=checkButton();   onClick='clearTimeout(theTimer);nextAd("+i+");'>"+i+"</div>";  
  }  
  dakularCode="<div   style='display:inline;   position:relative;left:"+buttonX+"px;   top:"+buttonY+"px;   z-index:1;'>"+dakularCode+"</div>";  
  document.write(dakularCode);  
  }  
  }  
  </SCRIPT>  
   
              <TABLE   style="RIGHT:   0px;   POSITION:   relative;   TOP:   -20px"   cellSpacing=0    
              cellPadding=0   border=0>  
                  <SCRIPT   language=javascript>  
  dakularButtons();  
  </SCRIPT>  
   
                  <TBODY>  
                  <TR   vAlign=top>  
                      <TD   vAlign=top><A    
                          onmouseover="displayStatusMsg();return   document.returnValue;"    
                          onmouseout="status='';"   href="javascript:jump2url()"><IMG    
                          style="BORDER-RIGHT:   #000000   1px   solid;   BORDER-TOP:   #000000   1px   solid;   FILTER:   revealTrans(duration=1,transition=18);   BORDER-LEFT:   #000000   1px   solid;   BORDER-BOTTOM:   #000000   1px   solid"    
                          height=178   alt=推荐景点   width=298   border=0    
                          name=imgUrlrotator></A></TD>  
                  </TR>  
                  <TR>  
                      <TD    
                      style="BORDER-RIGHT:   #000000   1px   solid;   BORDER-LEFT:   #000000   1px   solid;   BORDER-BOTTOM:   #000000   1px   solid"    
                      align=middle   bgColor=#f0f0f0   height=20><LABEL   id=linktext></LABEL>  
                          <SCRIPT   language=javascript>nextAd(1);</SCRIPT>  
                      </TD></TR></TBODY></TABLE></TD></TR>  
  </TBODY></TABLE>Top

相关问题

关键词

得分解答快速导航

  • 帖主:weiloon
  • elevenkey
  • elevenkey
  • theforever
  • goodstuday
  • zhuangyan2004

相关链接

  • Web开发类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo