JQuery banner 轮播

所属分类:媒体-幻灯片和轮播图

 378113  419  查看评论 (13)
分享到微信朋友圈
X
JQuery banner 轮播 ie兼容6

用JQuery操作DOM确实很方便,并且JQuery提供了非常人性化的API应付我们的各种需求,其中选择器在此示例-“JQuery实现图片轮播效果”上体现的尤为出色。大大简化了js的代码。


这里大概说一下整个流程:
1,将除了第一张以外的图片全部隐藏,
2,获取第一张图片的alt信息显示在信息栏,并添加点击事件
3,为4个按钮添加点击侦听,点击相应的按钮,用fadeOut,fadeIn方法显示图片
4,设置setInterval,定时执行切换函数

使用步骤

调用

<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>

html部分


<div id="banner">  
    <div id="banner_bg">       
    </div>
<!--标题背景-->
    <div id="banner_info"> 
    </div>
<!--标题-->
    <ul>   
        <li class="on">
            1
        </li>
        <li>
            2
        </li>
        <li>
            3
        </li>
        <li>
            4
        </li>
    </ul>
    <div id="banner_list">
        <a href="#" target="_blank"><img src="imgs/p1.jpg" title="jquery插件库1" alt="jquery插件库1"></a> <a href="#" target="_blank"><img src="imgs/p2.jpg" title="jquery插件库2" alt="jquery插件库2"></a> <a href="#" target="_blank"><img src="imgs/p3.jpg" title="jquery插件库3" alt="jquery插件库3"></a> <a href="#" target="_blank"><img src="imgs/p1.jpg" title="jquery插件库4" alt="jquery插件库4"></a>
    </div>
</div>	    	

css部分

<style type="text/css">
#banner { position: relative; width: 478px; height: 286px; border: 1px solid #666; overflow: hidden; }
#banner_list img { border: 0px; }
#banner_bg { position: absolute; bottom: 0; background-color: #000; height: 30px; filter: Alpha(Opacity=30); opacity: 0.3; z-index: 1000; cursor: pointer; width: 478px; }
#banner_info { position: absolute; bottom: 0; left: 5px; height: 22px; color: #fff; z-index: 1001; cursor: pointer }
#banner_text { position: absolute; width: 120px; z-index: 1002; right: 3px; bottom: 3px; }
#banner ul { position: absolute; list-style-type: none; filter: Alpha(Opacity=80); opacity: 0.8; z-index: 1002; margin: 0; padding: 0; bottom: 3px; right: 5px; }
#banner ul li { padding: 0px 8px; float: left; display: block; color: #FFF; background: #6f4f67; cursor: pointer; border: 1px solid #333; }
#banner ul li.on { background-color: #000; }
#banner_list a { position: absolute; }
<!--
让四张图片都可以重叠在一起-->
</style>

js部分

<script type="text/javascript">
    var t = n = 0,
    count;
    $(document).ready(function() {
        count = $("#banner_list a").length;
        $("#banner_list a:not(:first-child)").hide();
        $("#banner_info").html($("#banner_list a:first-child").find("img").attr('alt'));
        $("#banner_info").click(function() {
            window.open($("#banner_list a:first-child").attr('href'), "_blank")
        });
        $("#banner li").click(function() {
            var i = $(this).text() - 1; //获取Li元素内的值,即1,2,3,4
            n = i;
            if (i >= count) return;
            $("#banner_info").html($("#banner_list a").eq(i).find("img").attr('alt'));
            $("#banner_info").unbind().click(function() {
                window.open($("#banner_list a").eq(i).attr('href'), "_blank")
            }) $("#banner_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
            document.getElementById("banner").style.background = "";
            $(this).toggleClass("on");
            $(this).siblings().removeAttr("class");
        });
        t = setInterval("showAuto()", 4000);
        $("#banner").hover(function() {
            clearInterval(t)
        },
        function() {
            t = setInterval("showAuto()", 4000);
        });
    })
 
    function showAuto() {
        n = n >= (count - 1) ? 0 : ++n;
        $("#banner li").eq(n).trigger('click');
    }
</script>
相关插件-幻灯片和轮播图

js 3D立体相册

这是一个照片墙,通过鼠标点击来实现照片的播放,具有3D立体效果,代码简单有详细的注释。
  幻灯片和轮播图
 45228  394

jQuery手机响应式设计焦点图

jQuery手机响应式设计焦点图
  幻灯片和轮播图
 41245  405

jQuery仿腾讯图片新闻组图幻灯

jQuery仿腾讯图片新闻组图幻灯
  幻灯片和轮播图
 33182  410

基于jquey实现的轮播插件(原创)

基于jquey实现的轮播插件(支持左右箭头、圆点按钮、触摸切换、自动轮播)简单易用
  幻灯片和轮播图
 29194  279

讨论这个项目(13)回答他人问题或分享插件使用方法奖励jQ币 评论用户自律公约

    风花树下的仰望者 0
    2018/6/24 20:19:55
    这个怎么更改高度呢,我做的是全屏,width:100%;但是高度一直都是350,有木有人解答下,或者使用方法参数设置之类的.
        H。0
        2019/6/3 13:52:41
        !important
    回复
    stefan-雷吉兴(前端) 0
    2018/4/19 14:29:38
    我要是在下面图片img上面的a标签外面套一层li这个插件该怎么改? 回复
    真的可以! 0
    2017/5/31 14:47:15

    这个封面图不错,还有确实有bug

    回复
    Silent Guardian 0
    2017/4/19 21:21:46

    就冲这个封面图,我一定要给评论下

    回复
    怀念★往事 1
    2016/12/15 17:12:25

    主要是没清动画,要是快速点击1,2,3,4,过一会儿就出现错乱了。。。

    fadeOut和fadeIn加上

    .stop(true,true,true)

    就行了

        自古多情tm够娇情0
        2017/3/2 19:27:01

        不行哦,就算在fadeOut和fadeIn加上.stop(true,true,true),那么这个动画的效果就没了

        谭殷灵0
        2017/12/10 23:29:48

        当鼠标移开时,幻灯片不能实现每隔500ms循环播放

        stefan-雷吉兴(前端)0
        2018/4/19 14:44:33
        求助
    回复
    如意宝 | 陈赵宇 0
    2016/12/10 15:12:56
    恕我直言,这个是新手写的吧?明明jq写很简单的东西绕的这么复杂 回复
    金诺? 0
    2016/12/8 18:12:03
    什么浏览器有bug? 回复
    admade 0
    2016/9/2 17:09:32
    508252574 0
    2016/7/29 21:07:03
    济公 0
    2014/4/7 16:10:00

    不可以,建议把jquery下载到项目文件里

    回复
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
取消回复