`
shenyuc629
  • 浏览: 193778 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

JS实现图片轮播效果

    博客分类:
  • js
阅读更多
文章原创地址:http://www.shuonar.com/blog/b2b4a3fc-c7b2-44a5-8e52-0b51e4ab37d8.html

我们首先在HTML页面中建立一个div,div里面放需要轮播的东西.
<div class="home_picture_div" id="home_picture_div">
    <div id="banner_bg"></div>
    <div id="banner_info">说哪儿网</div>
    <ul>
    <li>1</li>
    <li class="on">2</li>
    <li>3</li>
    <li>4</li>
    </ul>
    <div id="banner_list">
    <a style="display: inline;" href="#" target="_blank"><img alt="说哪儿网" src="image/1.png"></a>
    <a style="display: inline;" href="#" target="_blank"><img alt="shuonar" src="image/2.png"></a>
    <a style="display: inline;" href="#" target="_blank"><img alt="shuonar.com" src="image/3.jpg"></a>
    <a style="display: inline;" href="#" target="_blank"><img alt="说客" src="image/4.jpg"></a>
</div>

下面对文本做CSS修饰。
    <style type="text/css">
        .home_picture_div {
    position: relative;
   
    width: 300px;
    height: 300px;
    float: left;
    overflow: hidden;

        }
        /* 图片列表的图片 */
#banner_list img{
border: 0px;
}
/* 图片标题背景 */
#banner_bg{
position: absolute;
bottom: 0;
background-color: #000000;
height: 30px;
filter:Alpha(Opacity=40);
opacity: 0.4;
z-index: 1000;
cursor: pointer;
width: 300px;
}
/* 图片标题 */
#banner_info{
position: absolute;
bottom: 0;
left: 5px;
height: 22px;
color: #FFF;
z-index: 1001;
cursor: pointer;
font-weight: bold;
}

.home_picture_div ul {
position:absolute;
list-style-type:none;
filter: Alpha(Opacity=80);
opacity:0.8;
border:1px solid #FFFFFF;
z-index:1002;
margin:0;
padding:0;
bottom:3px;
right:5px;
border-radius: 5px;
}

.home_picture_div ul li{
padding: 0px 8px;
float: left;
display: block;
color: #FFF;
border: #E5EAFF 1px solid;
background:  #454545;
cursor: pointer;
}
.home_picture_div ul li.on {
background:#5CACEE;
}
    </style>

下面用js对图片做轮播效果,我们在这里使用了jquery:

var t = n =0, count;

$(document).ready(function(){
$("#register_button").click(function(){
window.location.href = "nar_quick_register.html";
});
count = $("#banner_list a").length;   //4
$("#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");
});
$(".home_picture_div li").click(function(){
var i = $(this).text()-1;   //获取当前图片的索引值
n = i;
if(i>=count) return;
$("#banner_info").html($("#banner_list a").eq(i).find("img").attr("alt"));//给每张显示的图片加上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("home_picture_div").style.background = "";
$(this).toggleClass("on");
$(this).siblings().removeAttr("class");
});

t = setInterval("showAuto()",4000);
$("#home_picture_div").hover(
function(){
clearInterval(t);
},function(){
t = setInterval("showAuto()",4000);
});
});

function showAuto(){
n = n>=(count-1)?0: ++n;
$("#home_picture_div li").eq(n).trigger("click");
}
要查看该效果,可以到http://www.shuonar.com的首页查看图片轮播效果,这里是源代码。
分享到:
评论

相关推荐

    js实现图片轮播效果

    js实现图片轮播效果 不错的资源,大家可以下载看看

    JS实现图片轮播效果(绝对可用)

    绝对可用,利用javasScript实现图片轮播,具有1.自动播放(鼠标进入显示区域时停止播放) 2.左右焦点切换 3.底下小按钮切换 等功能

    javascript实现图片轮播效果

    本文实例介绍了javascript实现图片轮播效果的详细代码,分享给大家供大家参考,具体内容如下 效果图: 具体代码: &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;...

    JS实现图片轮播

    JS实现轮播图效果 内含HTML,CSS,JavaScript,图片,字体等

    JS实现图片轮播效果.docx

    HTML5+CSS+JAVASCRIPT综合实现,你只需另外准备好5副图片

    基于vue.js实现图片轮播效果

    主要为大家详细介绍了基于vue.js实现图片轮播效果,vue如何实现轮播图效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

    js实现图片轮播效果学习笔记

    本文实例为大家分享了js实现图片轮播效果的具体代码,供大家参考,具体内容如下 具体思路: 一、页面加载、获取整个容器、所有放数字索引的li及放图片列表的ul、定义放定时器的变量、存放当前索引的变量index 二、...

    Javascript实现图片轮播效果(二)图片序列节点的控制实现

    在上篇文章给大家介绍了Javascript实现图片轮播效果(一)让图片跳动起来,这里我们实现图片序列节点的跳转实现.在图片跳转的同时,我们一般需要知道他跳转的是哪个位置,这里就是图片序列节点需要跟图片一同显示.下面...

    JS实现页面图片轮播滚动效果

    JS实现页面图片轮播滚动效果 JS实现页面图片轮播滚动效果 JS实现页面图片轮播滚动效果 JS实现页面图片轮播滚动效果 JS实现页面图片轮播滚动效果

    【JavaScript源代码】JS实现简单图片轮播效果.docx

    JS实现简单图片轮播效果  本文实例为大家分享了JS实现简单图片轮播效果的具体代码,供大家参考,具体内容如下  左右按钮可点击左右移动显示图片进行无缝滚动 下面的小圆圈点击可跳到对应的图片索引 不进行上述...

    js使用swiper实现层叠轮播效果实例代码

    swiper实现轮播图几乎是没有一点点技术含量,但是用起来却很方便,包括对移动端的支持也很好。 由于简单这里当然就不会去详细介绍了,下面就来开始本文的正文内容 实现过程: 一.移动端-需求swiper 4.0.3实现层叠轮播 ...

    JS实现图片轮播效果实例详解【可自动和手动】

    主要介绍了JS实现图片轮播效果,结合完整实例形式分析了javascript可自动和手动轮播图的原理、布局与轮播功能相关实现技巧,需要的朋友可以参考下

    js实现的图片轮播器效果

    用javascript实现的图片轮播器效果

    前端图片轮播效果

    直接引用js文件,就可实现图片轮播效果,非常方便实用

    原生javascript实现图片轮播效果代码

    【原理简述】 html和css跟JQuery实现图片轮播效果里面的一样,略去。主要是几个公共函数,渐显和渐失,用闭包实现。至于主体逻辑部分,非常一般。 【程序源码】 贴几个公共函数算了,fadeIn,渐显,fadeOut,渐失 代码...

    Javascript实现图片轮播效果(一)让图片跳动起来

    图片轮播效果,在各大网站的首页都能看到,比较常见,下面脚本之家小编给大家介绍Javascript实现图片轮播效果(一)让图片跳动起来,需要的朋友参考下

    JS实现5张图片轮播效果

    用户控件直接就可用。好资源不解释。还有生成的sql数据库文件,运行一遍就自己建好数据库了,图片文件夹复制过去就可以。

Global site tag (gtag.js) - Google Analytics