html5jqueryl轮播图,基于JQuery的实现图片轮播效果(焦点图)
完整的演示代碼:
JQuery實現(xiàn)圖片輪播效果#banner {position:relative; width:478px; height:286px; border:1px solid #666; overflow:hidden; font-size:16px}
#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:4px; 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; height:20px}
#banner ul li { padding:0 8px; line-height:18px;float:left;display:block;color:#FFF;border:#e5eaff 1px solid;background-color:#6f4f67;cursor:pointer; margin:0; font-size:16px;}
#banner_list a{position:absolute;}
-->
【實例演示】
- 1
- 2
- 3
- 4
[Ctrl+A 全選 注:如需引入外部Js需刷新才能執(zhí)行]
【原理簡述】
這里大概說一下整個流程:
1,將除了第一張以外的圖片全部隱藏,
2,獲取第一張圖片的alt信息顯示在信息欄,并添加點擊事件
3,為4個按鈕添加點擊偵聽,點擊相應(yīng)的按鈕,用fadeOut,fadeIn方法顯示圖片
4,設(shè)置setInterval,定時執(zhí)行切換函數(shù)
【代碼說明】
filter(":visible") :獲取所有可見的元素
unbind():從匹配的元素中刪除綁定的事件
siblings:取得一個包含匹配的元素集合中每一個元素的所有唯一同輩元素的元素集合
例:找到每個div的所有同輩元素中帶有類名為selected的元素。
代碼如下:
Hello
Hello AgainAnd Again
執(zhí)行 $("div").siblings(),結(jié)果
代碼如下:
[
Hello
,And Again
]【程序源碼】
HTML部分:
代碼如下:
- 1
- 2
- 3
- 4
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; border:1px solid #fff;z-index:1002;
margin:0; padding:0; bottom:3px; right:5px;}
#banner ul li { padding:0px 8px;float:left;display:block;color:#FFF;border:#e5eaff 1px solid;background-color:#6f4f67;cursor:pointer}
#banner_list a{position:absolute;}
JS部分:
代碼如下:
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元素內(nèi)的值,即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);
$(this).css({"background":"#be2424",'color':'#000'}).siblings().css({"background":"#6f4f67",'color':'#fff'});
});
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');
}
總結(jié)
以上是生活随笔為你收集整理的html5jqueryl轮播图,基于JQuery的实现图片轮播效果(焦点图)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: STM32H743-梳理ADC模数转换器
- 下一篇: STM32H743+CubeMX-QSP