html部分 ???? ???? this?is?the?page一???? this?is?the?page二???? this?is?the?page三???? this?is?the?page四???? ???? css部分 *{???? padding:?0;???? margin:?0;???? }???? html,body{???? height:?一00%;???? }???? #container?{???? width:?一00%;???? height:?500px;???? overflow:?hidden;???? }???? .sections,.section?{???? height:一00%;???? }???? #container,.sections?{???? position:?relative;???? }???? .section?{???? background-color:?#000;???? background-size:?cover;???? background-position:?50%?50%;???? text-align:?center;???? color:?white;???? }???? #section0?{???? background-image:?url('images/一.jpg');???? }???? #section一?{???? background-image:?url('images/二.jpg');???? }???? #section二?{???? background-image:?url('images/三.jpg');???? }???? #section三?{???? background-image:?url('images/四.jpg');???? }?? .pages?li{list-style-type:none;width:一0px;height:一0px;border-radius:一0px;background-color:white}.pages?li:hover{box-shadow:0?0?5px?二px?white}.pages?li.active{background-color:orange;box-shadow:0?0?5px?二px?orange}.pages{position:absolute;z-index:999}.pages.horizontal{left:50%;transform:translateX(-50%);bottom:5px}.pages.horizontal?li{display:inline-block;margin-right:一0px}.pages.horizontal?li:last-child{margin-right:0}.pages.vertical{right:5px;top:50%;transform:translateY(-50%)}.pages.vertical?li{margin-bottom:一0px}.pages.vertical?li:last-child{margin-bottom:0} JS部分 jquery-一.一一.0.min.js"?type="text/javascript" //引入pageSwitch.min.js 如
十載的臺(tái)山網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。網(wǎng)絡(luò)營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整臺(tái)山建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“臺(tái)山網(wǎng)站設(shè)計(jì)”,“臺(tái)山網(wǎng)站推廣”以來,每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
*{??
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
第一張顯示沒問題,第二張以及之后的圖片顯示為空白。
首先,排除掉圖片路徑?jīng)]問題。(如果有問題,也不會(huì)網(wǎng)上提問了)
初步判斷,css靜態(tài)定位錯(cuò)誤。
css樣式固定在了第一張圖片,第二,第三之后的css定位不到,則顯示空白。
即使在js中是動(dòng)態(tài)定位的,但是請(qǐng)仔細(xì)檢查你的圖片ul的css的定位參數(shù)是否固定住了。
比如,設(shè)置了{(lán)left:0;}。
刪除掉css的錯(cuò)誤靜態(tài)定位,只保留js中的動(dòng)態(tài)定位可以解決第二張以及之后圖片空白問題。