有很多可供選擇的JQ插件,比如
在浠水等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作按需網(wǎng)站制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站建設(shè),成都全網(wǎng)營銷,外貿(mào)網(wǎng)站建設(shè),浠水網(wǎng)站建設(shè)費(fèi)用合理。
slider、bxslider、swipper等等,這些都是比較方便且功能強(qiáng)大的,例子可以參考官方的Demo
百度搜索下,有很多現(xiàn)成的基于jquery的幻燈插件,如果你要學(xué)習(xí)自己制作,就要先了解jquery的動(dòng)畫代碼。
引入文件:
link rel="stylesheet" href="css/jquery.fullPage.css"
script src="js/jquery.min.js"/script
!-- jquery.easings.min.js 用于 easing 參數(shù),也可以使用完整的 jQuery UI 代替,如果不需要設(shè)置 easing 參數(shù),可去掉改文件 --
script src="js/jquery.easings.min.js"/script
!-- 如果 scrollOverflow 設(shè)置為 true,則需要引入 jquery.slimscroll.min.js,一般情況下不需要 --
script src="js/jquery.slimscroll.min.js"/script
script src="js/jquery.fullPage.js"/script
div id="dowebok"
div class="section"
h3第一屏/h3
/div
div class="section"
h3第二屏/h3
/div
div class="section"
h3第三屏/h3
/div
div class="section"
h3第四屏/h3
/div
/div
每個(gè) section 代表一屏,默認(rèn)顯示“第一屏”,如果要指定加載頁面時(shí)顯示的“屏幕”,可以在對(duì)應(yīng)的 section 加上 class=”active”,如:
div class="section active"第三屏/div
同時(shí),可以在 section 內(nèi)加入 slide,如:
div id="dowebok"
div class="section"第一屏/div
div class="section"第二屏/div
div class="section"
div class="slide"第三屏的第一屏/div
div class="slide"第三屏的第二屏/div
div class="slide"第三屏的第三屏/div
div class="slide"第三屏的第四屏/div
/div
div class="section"第四屏/div
/div
調(diào)用的JavaScript代碼如下:
$(function(){
$('#dowebok').fullpage();
});
配置項(xiàng)如下圖所示:
方法,如下圖所示:
回調(diào)函數(shù),如下圖所示:
7
運(yùn)行效果如下圖所示:
*{??
margin:?0;??
padding:?0;??
}??
ul{??
list-style:none;??
}??
.slideShow{??
width:?620px;??
height:?700px;?????/*其實(shí)就是圖片的高度*/??
border:?1px?#eeeeee?solid;??
margin:?100px?auto;??
position:?relative;??
overflow:?hidden;????/*此處需要將溢出框架的圖片部分隱藏*/??
}??
.slideShow?ul{??
width:?2500px;??
position:?relative;?????/*此處需注意relative?:?對(duì)象不可層疊,但將依據(jù)left,right,top,bottom等屬性在正常文檔流中偏移位置,如果沒有這個(gè)屬性,圖片將不可左右移動(dòng)*/??
}??
.slideShow?ul?li{??
float:?left;?????/*讓四張圖片左浮動(dòng),形成并排的橫著布局,方便點(diǎn)擊按鈕時(shí)的左移動(dòng)*/??
width:?620px;??
}??
.slideShow?.showNav{?????/*用絕對(duì)定位給數(shù)字按鈕進(jìn)行布局*/??
position:?absolute;??
right:?10px;??
bottom:?5px;??
text-align:center;??
font-size:?12px;??????
line-height:?20px;??
}??
.slideShow?.showNav?span{??
cursor:?pointer;??
display:?block;??
float:?left;??
width:?20px;??
height:?20px;??
background:?#ff5a28;??
margin-left:?2px;??
color:?#fff;??
}??
.slideShow?.showNav?.active{??
background:?#b63e1a;??
}??
js代碼規(guī)范:
script?src="../../../jQuery/js/jquery-2.1.4.js"/script?script?type="text/javascript"??
$(document).ready(function(){??????
var?slideShow=$(".slideShow"),????????????????????????????????????????????????????????????????????//獲取最外層框架的名稱?????
ul=slideShow.find("ul"),???????????????
showNumber=slideShow.find(".showNav?span"),??????????????????????????????????????????????//獲取按鈕??????????
oneWidth=slideShow.find("ul?li").eq(0).width();????????????????????????????????????????//獲取每個(gè)圖片的寬度??????????
var?timer=null;?????????????????????????????????????????????????????????????????????????????????????//定時(shí)器返回值,主要用于關(guān)閉定時(shí)器??????????
var?iNow=0;?????????????????????????????????????????????????????????????????????????????????????????//iNow為正在展示的圖片索引值,當(dāng)用戶打開網(wǎng)頁時(shí)首先顯示第一張圖,即索引值為0??????????????????
showNumber.on("click",function(){??????????????????????????????????????????????????????//為每個(gè)按鈕綁定一個(gè)點(diǎn)擊事件???????????????????
$(this).addClass("active").siblings().removeClass("active");??????????????????//按鈕點(diǎn)擊時(shí)為這個(gè)按鈕添加高亮狀態(tài),并且將其他按鈕高亮狀態(tài)去掉??????????????
var?index=$(this).index();????????????????????????????????????????????????????????????????//獲取哪個(gè)按鈕被點(diǎn)擊,也就是找到被點(diǎn)擊按鈕的索引值??????????????
iNow=index;??????????????
ul.animate({????"left":-oneWidth*iNow,???????????????????????????????//注意此處用到left屬性,所以u(píng)l的樣式里面需要設(shè)置position:?relative;?讓ul左移N個(gè)圖片大小的寬度,N根據(jù)被點(diǎn)擊的按鈕索引值iNOWx確定????????????
})????????
});?????????????????
function?autoplay(){??????
timer=setInterval(function(){??????????????????????????????????????????????//打開定時(shí)器?????????????
iNow++;?????????????????????????????????????????????????????????????????????????//讓圖片的索引值次序加1,這樣就可以實(shí)現(xiàn)順序輪播圖片?????????????
if(iNowshowNumber.length-1){??????????????????????????????????????//當(dāng)?shù)竭_(dá)最后一張圖的時(shí)候,讓iNow賦值為第一張圖的索引值,輪播效果跳轉(zhuǎn)到第一張圖重新開始??????????????????
iNow=0;?}??????????????
showNumber.eq(iNow).trigger("click");??????????????????????????????????//模擬觸發(fā)數(shù)字按鈕的click??????????
},2000);??????????????????????????????????????????????????????????????????????//2000為輪播的時(shí)間??
}?????
autoplay();?????
slideShow.hover(?function(){clearInterval(timer);},autoplay);?????另外注意setInterval的用法比較關(guān)鍵。??
})??
/script??
主體代碼:
[html]?view?plain?copy?print?
body??
div?class="slideShow"??
!--圖片布局開始--??
ul??
lia?href="#"img?src="images/view/111.jpg"http://a/li??
lia?href="#"img??src="images/view/112.jpg"?//a/li??
lia?href="#"img?src="images/view/113.jpg"?//a/li??
lia?href="#"img??src="images/view/114.jpg"?//a/li??
/ul??
!--圖片布局結(jié)束--??
!--按鈕布局開始--??
div?class="showNav"??
span?class="active"1/span??
span2/span??
span3/span??
span4/span??
/div??
!--按鈕布局結(jié)束--??
/div??
/body
您好,如果自適應(yīng)窗口的輪播圖,加上自動(dòng)輪播。
div?id='banner'
ul
li/li
li/li
li/li
/ul
/div
//如果輪播圖寬度占滿全屏的話。并且是類似于上述html的格式。
var?index?=?0;
var?oBanner?=?$('#banner');
var?iLiLength?=?oBanner.find('li').length;
setInterval(function(){
if?(i??iLiLength)){
i?=?0;
}
i++;
oUl.animate({
left:?-index?*?$(window).width()
},1000);
},1000);
我有代碼,如果不是學(xué)網(wǎng)頁的,我怕你看不懂!
!doctype?html
html
head
meta?charset="utf-8"
titlejQuery圖片輪播代碼/title
style
.flexslider?{
margin:?0px?auto?20px;
position:?relative;
width:?100%;
height:?482px;
overflow:?hidden;
zoom:?1;
}
.flexslider?.slides?li?{
width:?100%;
height:?100%;
}
.flex-direction-nav?a?{
width:?70px;
height:?70px;
line-height:?99em;
overflow:?hidden;
margin:?-35px?0?0;
display:?block;
background:?url(images/ad_ctr.png)?no-repeat;
position:?absolute;
top:?50%;
z-index:?10;
cursor:?pointer;
opacity:?0;
filter:?alpha(opacity=0);
-webkit-transition:?all?.3s?ease;
border-radius:?35px;
}
.flex-direction-nav?.flex-next?{
background-position:?0?-70px;
right:?0;
}
.flex-direction-nav?.flex-prev?{
left:?0;
}
.flexslider:hover?.flex-next?{
opacity:?0.8;
filter:?alpha(opacity=25);
}
.flexslider:hover?.flex-prev?{
opacity:?0.8;
filter:?alpha(opacity=25);
}
.flexslider:hover?.flex-next:hover,
.flexslider:hover?.flex-prev:hover?{
opacity:?1;
filter:?alpha(opacity=50);
}
.flex-control-nav?{
width:?100%;
position:?absolute;
bottom:?10px;
text-align:?center;
}
.flex-control-nav?li?{
margin:?0?2px;
display:?inline-block;
zoom:?1;
*display:?inline;
}
.flex-control-paging?li?a?{
background:?url(images/dot.png)?no-repeat?0?-16px;
display:?block;
height:?16px;
overflow:?hidden;
text-indent:?-99em;
width:?16px;
cursor:?pointer;
}
.flex-control-paging?li?a.flex-active,
.flex-control-paging?li.active?a?{
background-position:?0?0;
}
.flexslider?.slides?a?img?{
width:?100%;
height:?482px;
display:?block;
}
/style
/head
body
br/br/br/
!--?輪播廣告?--
div?id="banner_tabs"?class="flexslider"
ul?class="slides"
li
a?title=""?target="_blank"?href="#"
img?width="1920"?height="482"?alt=""?style="background:?url(images/banner1.jpg)?no-repeat?center;"?src="images/alpha.png"
/a
/li
li
a?title=""?href="#"
img?width="1920"?height="482"?alt=""?style="background:?url(images/banner2.jpg)?no-repeat?center;"?src="images/alpha.png"
/a
/li
li
a?title=""?href="#"
img?width="1920"?height="482"?alt=""?style="background:?url(images/banner3.jpg)?no-repeat?center;"?src="images/alpha.png"
/a
/li
/ul
ul?class="flex-direction-nav"
lia?class="flex-prev"?href="javascript:;"Previous/a/li
lia?class="flex-next"?href="javascript:;"Next/a/li
/ul
ol?id="bannerCtrl"?class="flex-control-nav?flex-control-paging"
lia1/a/li
lia2/a/li
lia2/a/li
/ol
/div
script?src="js/jquery-1.10.2.min.js"/script
script?src="js/slider.js"/script
script?type="text/javascript"
$(function()?{
var?bannerSlider?=?new?Slider($('#banner_tabs'),?{
time:?5000,
delay:?400,
event:?'hover',
auto:?true,
mode:?'fade',
controller:?$('#bannerCtrl'),
activeControllerCls:?'active'
});
$('#banner_tabs?.flex-prev').click(function()?{
bannerSlider.prev()
});
$('#banner_tabs?.flex-next').click(function()?{
bannerSlider.next()
});
})
/script
/body
/html