图片轮播

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            *{
                margin: 0px;
                padding: 0px;
            }
            #stage{
                width: 300px;
                height: 200px;
                border: 10px solid black;
                margin: 300px;
                position: relative;
                overflow: hidden;
            }
            #ad-banner{
                width: 1500px;
                height: 200px;
                background-color: brown;
                position: relative;
                z-index: 980;
                /*margin-left: -300px;*/
            }
            .ad{
                position: relative;
                width: 300px;
                height: 200px;
                float: left;
                color: white;
                font-size: 100px;
                text-align: center;
                line-height: 200px;
                z-index: 990;
            }
            #btn-left,#btn-right{
                width: 20px;
                height: 30px;
                position: absolute;
                top: 85px;
                background-color: black;
                z-index: 999;
                color: white;
                opacity: 0.5;
                text-align: center;
                line-height: 30px;
                font-size: 15px;
                font-weight: bold;
            }
            #btn-left{
                left: 0px;
            }
            #btn-right{
                right: 0px;
            }

            #btn-left:hover,#btn-right:hover{
                opacity: 0.8;
                cursor: pointer;
            }
        </style>
    </head>
    <body>
        <div id="stage">

            <div id="btn-right" onclick="moveLeftclick()">></div>
            <div id="btn-left" onclick="moveRightclick()"><</div>
            <div id="ad-banner">
                <div class="ad" style="background-color: hotpink;">1</div>
                <div class="ad" style="background-color: darkcyan">2</div>
                <div class="ad" style="background-color: coral">3</div>
                <div class="ad" style="background-color: #4CAE4C">4</div>
                <div class="ad" style="background-color: blueviolet">5</div>
            </div>
        </div>
    </body>
</html>
<script>
    var ad_banner = document.getElementById("ad-banner");
    var arr = [];
    var count = 1;
    function moveLeftclick(){
        if(count == 5){
            return false;
        }else{
            arr.push(window.setInterval("moveLeft()",20));
        }
    }

    function moveLeft(){
        ad_banner.style.marginLeft = ad_banner.offsetLeft - 10 + "px";
        if(ad_banner.offsetLeft == -300 * count)
        {
            for(var x in arr){
                window.clearInterval(arr[x]);
            }
            count++;
        }
    }
    function moveRightclick() {
        if (count == 1) {
            return false;
        } else {
            arr.push(window.setInterval(moveRight, 20));
        }

    }

    function moveRight() {
        ad_banner.style.marginLeft = ad_banner.offsetLeft + 10 + "px";
        if (ad_banner.offsetLeft == -300 * (count - 2)) {
            for (var x in arr) {
                window.clearInterval(arr[x]);
            }
            count--;
        }

    }

    window.setInterval("moveLeftclick()",5000);
</script>
时间: 2024-08-06 14:26:35

图片轮播的相关文章

CSS3图片轮播效果

原文:CSS3图片轮播效果 在网页中用到图片轮播效果,单纯的隐藏.显示,那再简单不过了,要有动画效果,如果是自己写的话(不用jquery等),可能要费点时间.css3的出现,让动画变得不再是问题,而且简单易用.下面介绍我用css3与js写的一个图片轮播效果. 一般图片轮播就是三四张图片: <div class="wrap"> <div class="carousel"> <div><img src="http://

UISCrollView —— 图片轮播器封装实现(三)——(第三讲)

1.分析 利用xib布局,然后自定义一个UIView,解析xib,然后利用控制器传入数据,将其加载到控制器的view上展示即可 2. 程序结构 3. 代码具体实现 1>  xib文件 2>  创建类 XMGPageView,然后将其与xib文件关联,选中xib文件,然后设置下文中 " custom class " 为定义的类,让其来管理xib 1>    (如图,设置xib与类关联) 2>  XMGPageView.h 文件中,声明分页图片数组属性,及其一个快速

ionic 图片轮播问题

1.使用ion-slide可以实现图片轮播,但是如果在html中仅仅增加ion-slide是远远不够的,会出现两个问题: (注:使用的是angularjs.首先需要在,js文件中注入:$ionicSlideBoxDelegate) 一.有时候会出现图片无法加载出来.解决办法是: 在相应的controller文件增加 $ionicSlideBoxDelegate.update(); 二.轮播至最后一个不轮播的问题,解决的办法是: 在相应的controller文件增加 $ionicSlideBoxD

js图片轮播与索引变色

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

IOS 图片轮播实现原理 (三图)

IOS 图片轮播实现原理的一种 图片轮播所要实现的是在一个显示区域内通过滑动来展示不同的图片. 当图片较少时我们可以采用在滚动视图上添加很多张图片来实现. 但是如果图片数量较多时,一次性加载过多图片会浪费内存,影响性能. 因此我们要采取适当地方法来实现图片的轮播. 下面我们只是简单的介绍很多方法中的一种简单的实现原理. 一 二 三 四 五 六 七

面向对象编程---图片轮播

今天复习了一下面向对象编程,下面是我的效果图 看着这个图片你会觉得这没有什么,那么上代码: html部分: 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <style> 7 ul,ol,li{padding:0;margin:0;li

ionic 图片轮播ion-slide-box问题

1.使用ion-slide可以实现图片轮播,但是如果在html中仅仅增加ion-slide是远远不够的,会出现两个问题: (注:使用的是angularjs.首先需要在,js文件中注入:$ionicSlideBoxDelegate) 一.有时候会出现图片无法加载出来.解决办法是: 在相应的controller文件增加 $ionicSlideBoxDelegate.update(); 二.轮播至最后一个不轮播的问题,解决的办法是: 在相应的controller文件增加 $ionicSlideBoxD

一分钟搞定AlloyTouch图片轮播

一分钟搞定AlloyTouch图片轮播 轮播图也涉及到触摸和触摸反馈,同时,AlloyTouch可以把惯性运动打开或者关闭,并且设置min和max为运动区域,超出会自动回弹.除了一般的竖向滚动,AlloyTouch也可以支持横向滚动,甚至任何属性的运动,因为它的设计的本质就是属性无关,触摸可以反馈到任何属性的运动.所以AlloyTouch制作各种各样的轮播组件还是得心应手. 第一种轮播图如上图所示.下面开始实现的过程. 第0秒 <div id="carousel-container&quo

20款带左右箭头的焦点图片轮播特效代码

20款带左右箭头的焦点图片轮播特效代码分享 html5带倒影3D图片叠加轮播切换特效 jQuery slide图片自动轮播滚动插件 jQuery焦点图插件带按钮控制图片轮播滚动代码 jquery仿hao123带新闻标题图片轮播滚动效果 jQuery仿瑞丽全屏透明遮罩图片轮播滚动代码 jQuery带网上开户表单的焦点图轮播代码 jquery左右箭头控制带缩略图片轮播切换 jQuery responsiveslides.js响应式图片轮播特效 jQuery OwlCarousel图片滚动插件世界杯图

UIScrollView实现图片轮播器及其无限循环效果

图片轮播器: 一.实现效果 实现图片的自动轮播            二.实现代码 storyboard中布局 代码: 1 #import "YYViewController.h" 2 3 @interface YYViewController () <UIScrollViewDelegate> 4 @property (weak, nonatomic) IBOutlet UIScrollView *scrollview; 5 /** 6 * 页码 7 */ 8 @prop