CNZZ首页四张图片平滑切换,优化了页面代码,更有利于SEO优化

 

演示地址见 http://www.cnzz.com/ 优化了部分页面代码

源代码下载:http://files.cnblogs.com/rednut/仿CNNZ首页四幅切换.rar

html:

< div  id ="smothSwitch" >
    
< div  id ="adImg" >
        
< href ="1111" >< img  src ="images/four-ad_01.gif"   /></ a >
        
< href ="2222" >< img  src ="images/four-ad_02.gif"   /></ a >
        
< href ="3333" >< img  src ="images/four-ad_03.gif"   /></ a >
        
< href ="4444" >< img  src ="images/four-ad_04.gif"   /></ a >
    
</ div >
    
< ul  id ="adText" >
        
< li > CNZZ站长统计 </ li >
        
< li > CNZZ全景统计 </ li >
        
< li > CNZZ站长助手 </ li >
        
< li > CNZZ数据中心 </ li >
    
</ ul >
</ div >

 

 

图片及链接直接放到了页面里面,并没有动态写入,这应该利于搜索引擎的抓取吧 ^-^

 

CSS:

 

ExpandedBlockStart.gif ContractedBlock.gif #smothSwitch ul, #smothSwitch li {} { margin:0; padding:0; list-style:none;}
ExpandedBlockStart.gifContractedBlock.gif#smothSwitch
{} { width:590px; float:left; border:1px solid #C9D3E0;}
ExpandedBlockStart.gifContractedBlock.gif#smothSwitch #adImg
{} { width:100%; height:119px; float:left; clear:both; overflow:hidden; position:relative;}
ExpandedBlockStart.gifContractedBlock.gif#smothSwitch #adImg a
{} {}
ExpandedBlockStart.gifContractedBlock.gif#smothSwitch #adImg img
{} { border:0; float:left; clear:both; /**//*filter:Alpha(opacity=50); opacity:0.5;*/}
ExpandedBlockStart.gifContractedBlock.gif#smothSwitch ul
{} { width:100%; float:left; clear:both; height:34px; background:url(../images/grey-bg.gif) repeat-x;}
ExpandedBlockStart.gifContractedBlock.gif#smothSwitch ul li
{} { width:147px; height:33px; float:left; font-size:12px; line-height:30px; text-align:center; font-family:Arial; cursor:pointer;}
ExpandedBlockStart.gifContractedBlock.gif#smothSwitch ul .focus
{} { background:url(../images/grey-pic.gif) no-repeat;}

 

javascript:

 

var  timeDelay  =   5 // 定义图片延迟显示的秒数
var  currentId  =   0
var  slidint;

ExpandedBlockStart.gifContractedBlock.gif
function  $(p) {
    
return document.getElementById(p);    
}


// 控制当前焦点按钮样式
ExpandedBlockStart.gifContractedBlock.gif
function  setFocus(n) {
    
var imgList = document.getElementById("adImg").getElementsByTagName("img");    
ExpandedSubBlockStart.gifContractedSubBlock.gif    
for (i=0;i<imgList.length;i++){    
        imgList[i].style.opacity 
= 0;
        imgList[i].style.filter 
= "alpha(opacity=0)";
    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
for ( i=0;i<imgList.length;i++ ){
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if ( i == n ){
            $(
"adText").getElementsByTagName("li")[i].className = "focus";
            $(
"adImg").getElementsByTagName("a")[i].style.display = "block";
        }

ExpandedSubBlockStart.gifContractedSubBlock.gif        
else{
            $(
"adText").getElementsByTagName("li")[i].className = "";
            $(
"adImg").getElementsByTagName("a")[i].style.display = "none";
        }

    }

    imgAlpha();
}


// 图片渐显
ExpandedBlockStart.gifContractedBlock.gif
function  imgAlpha() {
    
var temp = 0;
    
var temp2 = 0;
    
var imgList = document.getElementById("adImg").getElementsByTagName("img");    
ExpandedSubBlockStart.gifContractedSubBlock.gif    
function alphaUp(){
        
if( temp < 1 && temp2 <100 )
ExpandedSubBlockStart.gifContractedSubBlock.gif        
{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
for (i=0;i<imgList.length;i++){
            imgList[i].style.opacity 
= temp;
            imgList[i].style.filter 
= "alpha(opacity="+ temp2 +")";
            }

            temp 
+= 0.05;
            temp2 
+= 5;
        }

    }

    a 
= setInterval(alphaUp,10);
}


// 播放下一张
ExpandedBlockStart.gifContractedBlock.gif
function  playnext() {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
if(currentId == 3){
        currentId 
= 0;
    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    
else{
        currentId
++;
    }
;
    setFocus(currentId);
    playit();
}


ExpandedBlockStart.gifContractedBlock.gif
function  playit() {
    slidint 
= setTimeout(playnext,timeDelay*1000);
}


ExpandedBlockStart.gifContractedBlock.gif
function  stopit() {
    clearTimeout(slidint);
}


// 鼠标滑过及离开图片的操作
ExpandedBlockStart.gifContractedBlock.gif
function  checkMouseOver() {
ExpandedSubBlockStart.gifContractedSubBlock.gif    $(
"adImg").onmouseover = function(){
        stopit();
    }

ExpandedSubBlockStart.gifContractedSubBlock.gif    $(
"adImg").onmouseout = function(){
        playit();
    }

}


// 点击标签按钮后的操作
ExpandedBlockStart.gifContractedBlock.gif
function  checkClick() {
    
var btnList = document.getElementById("adText").getElementsByTagName("li");
ExpandedSubBlockStart.gifContractedSubBlock.gif    
for (i=0;i<btnList.length;i++){    
        btnList[i].id 
= "tempBtn"+i;
ExpandedSubBlockStart.gifContractedSubBlock.gif        btnList[i].onclick 
= function(){
            currentId 
= this.id.slice(-1);
            setFocus(currentId);
            stopit();
            playit();
        }

    }

    
}


ExpandedBlockStart.gifContractedBlock.gif
function  smothSwitchAd() {
    $(
"adText").getElementsByTagName("li")[0].className = "focus";
    checkMouseOver();
    checkClick();
    playit();
}


window.onload 
=  smothSwitchAd;

转载于:https://www.cnblogs.com/rednut/archive/2009/05/01/1447332.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值