| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 518 人关注过本帖, 1 人收藏
标题:洗牌式新闻图片切换 多浏览器兼容
只看楼主 加入收藏
dsthy
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-11-7
结帖率:100%
收藏(1)
已结贴  问题点数:20 回复次数:1 
洗牌式新闻图片切换 多浏览器兼容
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<style>
*{ margin:0; padding:0; font-size:13px; border:0; font:宋体,arial}
li{ list-style-type:none}
.imgbox{ position:absolute;left:300px;top:50px; width:200px; height:130px; position:relative}
.img{ position:absolute; width:200px; height:130px}
.img li{ display:block; position:absolute; width:200px; height:130px}
.img div{ width:400px; height:130px; overflow:hidden; position:relative; left:-200px}
.img span{ display:block; width:700px; height:130px; position:absolute}
.img img{ width:200px; height:130px; position:absolute; left:200px}
.buttom{ position:absolute; left:10px; top:115px; overflow:hidden; z-index:4 ; width:190px}
.buttom li{ display:block; float:right; width:20px; border:solid 1px #000000; text-align:center; line-height:15px; background:#FF0; color: #000; cursor:pointer}
#a5{ background:#093}
</style>
<script>
var long = 200;//行进的距离 是图片的宽度
var step = 3 ;//图片移动的像素
var n = 6 ;//图片个数,根据你设置的图片个数而定,我用了6个图片
var start = 0;
var number = n;
var id = "box" + n ;
var direction = "left" ;
slideleft();
function slideleft(){
    function slide(){
            if( direction == "left" ){
                start = start + step;
                document.getElementById(id).scrollLeft = start;
                if( start >= long){
                    direction = "right"    ;
                    transposition();
                    buttoncolor(n);
                    }
                }
            if(direction == "right"){
                start = start - step;
                document.getElementById(id).scrollLeft = start;
                if(start <= 0){
                    direction = "left" ;
                    n = n-1 ;
                    if(n == 0){ n = number;}
                    id = "box" + n ;
                    }
                }
        }
    timer = setInterval(slide,20);
    }
function transposition(){
    var myul = document.getElementById("img");//获取id 为 "img" 的ul容器
    var newli = document.createElement("li"); //创建一个新的li
    var li01 = myul.getElementsByTagName("li").item(0);//获取ul容器中的第0条li
    var li04 = myul.getElementsByTagName("li").item(number-1);//获取ul容器中的最后一条li
    newli.innerHTML = li04.innerHTML; //将最后的li中的HTML代码赋给新创建的li
    myul.removeChild(li04);//删除最后一条li
    myul.insertBefore(newli,li01); //将新创建的li添加到第0条前
    }
function buttoncolor(num){
    for(i=1;i<=number;i++){
        id2 = "a" + i ;
        document.getElementById(id2).style.background = "#FF0" ;
        }
    var n = num  ;
    n = n -1 ;
    if(n == 0){ n = number;}
    var id2 = "a" + n ;
    document.getElementById(id2).style.background = "#093" ;
    }
function imgmouseover(){
    clearInterval(timer);
    }
function imgmouseout(){
    slideleft() ;
    }
function buttonmouseover(buttonnum){
    clearInterval(timer);
    for(var i=1;i<=number;i++){
         id1 = "box" + i;
        document.getElementById(id1).scrollLeft = 0 ;
        document.getElementById(id1).style.display = "none" ;
        }
    var id2 = "box" + buttonnum ;
    document.getElementById(id2).style.display = "block"  ;
    var num = buttonnum +1 ;
    if( num == number+1){ num = 1;}
    buttoncolor(num);
    }
function buttonmouseout(){
    for(var i=1;i<=number;i++){
         id2 = "box" + i ;
        document.getElementById(id2).style.display = "block" ;
        }
    slideleft();
    }
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>洗牌式新闻图片切换 多浏览器兼容 新闻中心胡勇编制</title>
</head>
<body>
<div  class="imgbox">
    <ul class="img" id="img" onmouseover="imgmouseover()" onmouseout="imgmouseout()">
       <li id="li1"><div id="box1"><span><img src="images/an06.jpg" /></span></div></li>
       <li id="li2"><div id="box2"><span><img src="images/an05.jpg" /></span></div></li>
       <li id="li3"><div id="box3"><span><img src="images/an04.jpg" /></span></div></li>
       <li id="li4"><div id="box4"><span><img src="images/an03.jpg" /></span></div></li>
       <li id="li5"><div id="box5"><span><img src="images/an02.jpg" /></span></div></li>
       <li id="li6"><div id="box6"><span><img src="images/an01.jpg" /></span></div></li>
    </ul>
    <ul class="buttom" onmouseout="buttonmouseout()">
        <li id="a1" onmouseover="buttonmouseover(1)" >6</li>
        <li id="a2" onmouseover="buttonmouseover(2)" >5</li>
        <li id="a3" onmouseover="buttonmouseover(3)" >4</li>
        <li id="a4" onmouseover="buttonmouseover(4)" >3</li>
        <li id="a5" onmouseover="buttonmouseover(5)" >2</li>
        <li id="a6" onmouseover="buttonmouseover(6)" >1</li>
    </ul>
</div>
</body>
</html>

[ 本帖最后由 dsthy 于 2012-11-7 15:08 编辑 ]
搜索更多相关主题的帖子: html 浏览器 absolute position relative 
2012-11-07 14:36
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:20 
学习了, 效果不错!!!
2012-11-07 20:32
快速回复:洗牌式新闻图片切换 多浏览器兼容
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027954 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved