CSS实现图片轮播

html-css010

CSS实现图片轮播,第1张

刚学 js 时 写的 图片滚动图!~

当参考吧, 如果没 价值 当我没发!

注释就算了吧!~ 麻烦  我还得 从新 解读一遍代码 ,

有价值的话,自己慢慢看吧  我写的 特别简单

<!DOCTYPE html>

<html>

<head>

    <title></title>

    <style type="text/css">

        *{padding:0px margin:0px list-style: none}

        ul li{float: left}

        img{display: block float: left}

        #butl{ width:80px height: 220px  background: linear-gradient(to right,#ccc, transparent) opacity: 0.9 position: absolute left: 0px top: 0px  z-index: 99 line-height: 220px text-align: centerfont-size: 50px cursor:pointerfont-family:  Microsoft Sans Serif, WenQuanYi Micro Hei, sans-serif}

        #butr{ width:80px height: 220px background: linear-gradient(to left,#ccc, transparent) opacity: 0.9 position: absolute right: 0px top: 0px  z-index: 99 line-height: 220px text-align: center font-size: 50pxcursor:pointer font-family:  Microsoft Sans Serif, WenQuanYi Micro Hei, sans-serif}

    </style>

    <script type="text/javascript">

    window.onload=function(){

        var oimg_l=document.getElementById('img_left')

        var obutl=document.getElementById('butl')

        var obutr=document.getElementById('butr')

        var buts=2

        var timer=null

        obutl.onclick=function()

        {

            buts=-2

        }

        obutr.onclick=function()

        {

            buts=2

        }

        oimg_l.innerHTML=oimg_l.innerHTML+oimg_l.innerHTML

        function sunmer(){

            oimg_l.style.left=oimg_l.offsetLeft+buts+'px'

            if(oimg_l.style.left=='-1408px'){oimg_l.style.left='0px'}

            if(oimg_l.style.left>0+'px'){oimg_l.style.left='-1408px'}

        }

        timer=setInterval(sunmer,30)

        oimg_l.onmouseover=function()

        {

            clearInterval(timer)

        }

        oimg_l.onmouseout=function()

        {

            timer=setInterval(sunmer,30)

        }    

}

    </script>

</head>

<body>

<div style=" width: 1408px overflow: hidden position: relative height: 220px background: red margin:50px auto">

    <div id="butl"><</div>

        <ul id="img_left"  style="position: absolute left:0px top: 0px width: 2816px z-index: 1">

            <li><a href="#"><img src="./img2/1.jpg"></a></li>

            <li><a href="#"><img src="./img2/2.jpg"></a></li>

            <li><a href="#"><img src="./img2/3.jpg"></a></li>

            <li><a href="#"><img src="./img2/4.jpg"></a></li>

        </ul>

    <div id="butr">></div>

</div>

</body>

</html>

CSS能更换的图片,只能存在于样式中。所以,这个图片也只能是背景图片。

一般是结合:hover来实现的。例如:

.mydiv{

background:图片1  no-repeat

height:100px

widht:100px

}

.mydiv:hover{

background:图片2  no-repeat

}

这样就实现了图片1和图片2的鼠标移上去的切换。

CSS层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。CSS不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。

只是CSS可能整出来的不好啊,还是要加上js才更好。但是这个也可以,CSS的。

div {

border: 1px solid red

width: 500px

height: 280px

/*background-image:url(..//pic/newimages/1.png)*/

position: relative

animation: firstone 10s infinite

animation-direction: alternate

-webkit-animation: firstone 10s infinite

-webkit-animation-direction: alternate

}

@keyframes firstone {

0% {

background-image: url(..//pic/newimages/1.png)

left: 20px

top: 0

}

25% {

background-image: url(..//pic/newimages/8.jpg)

left: 280px

top: 0

}

50% {

background-image: url(..//pic/newimages/7.jpg)

left: 280px

top: 280px

}

75% {

background-image: url(..//pic/newimages/15.jpg)

left: 20px

top: 280px

}

20% {

background-image: url(..//pic/newimages/19.jpg)

left: 20px

top: 0

}

}

@-webkit-keyframes firstone {

0% {

background-image: url(..//pic/newimages/2.png)

left: 0

top: 0

}

25% {

background-image: url(..//pic/newimages/8.jpg)

left: 280px

top: 0

}

50% {

background-image: url(..//pic/newimages/7.jpg)

left: 280px

top: 280px

}

75% {

background-image: url(..//pic/newimages/15.jpg)

left: 0

top: 280px

}

20% {

background-image: url(..//pic/newimages/19.jpg)

left: 0

top: 0

}

}

里面写一个空的div就可以了,放图片就是自己放吧。