Jquery 實(shí)現(xiàn)圖片輪換
網(wǎng)站首頁(yè)沒有一點(diǎn)動(dòng)畫怎么可以,我以前用過(guò)Flash As3做過(guò)圖片切換,效果非常不錯(cuò),可是麻煩,改變起來(lái)麻煩。一直都想自己做個(gè)圖片切換效果,總認(rèn)為比較麻煩,今天自己實(shí)踐了一下,其實(shí)還比較簡(jiǎn)單。不過(guò)有個(gè)小問題,IE8不兼容模式下 設(shè)置有透明效果的div 樣式添加失效了,但是我用谷歌,IE8兼容測(cè)試都o(jì)k。
反正是給自己記錄的,也不多話了,js沒有與頁(yè)面分離,也沒有做出插件。一個(gè)網(wǎng)站要不了幾個(gè)這種效果,先實(shí)現(xiàn)了再說(shuō)吧。最后的效果還是很高大上的。
頁(yè)面+JS代碼
<script type="text/javascript">
var picCurrent = 1;
var picTotal = 8;
var interval; //自動(dòng)運(yùn)行
function picChange(current) {
//停止當(dāng)前動(dòng)畫
if ($("#divImg").is(":animated")) { $("#divImg").stop(); }
picCurrent = current;
//為當(dāng)前選擇的設(shè)置樣式
$("#divLink").find("a").removeClass("picselect")
$("#divLink").find("a[title='" + picCurrent + "']").addClass("picselect");
//設(shè)置下面的圖片說(shuō)明
var remark = "<a href=\"images/pic" + picCurrent + ".jpg\">";
switch (picCurrent) {
case 1: remark += " 菊花〔拉丁學(xué)名:Dendranthema morifolium(Ramat. )Tzvel.〕,常用chrysanthemum。菊花是菊科,菊屬多年生草本... "; break;
default: remark += picCurrent + "測(cè)試說(shuō)明"; break;
}
remark += "</a>";
$("#picremark").html(remark);
//運(yùn)行動(dòng)畫
$("#divImg").animate({ left: -((picCurrent - 1) * 1000) + "px" }, "1000");
return false;
}
//暫不需使用
function PicPer() {
if (picCurrent > 1) {
picCurrent--;
}
else {
picCurrent = picTotal;
}
picChange(picCurrent);
}
//下一張
function PicNext() {
if (picCurrent == picTotal) {
picCurrent = 1
}
else {
picCurrent++;
}
picChange(picCurrent);
}
//自動(dòng)切換圖片
function PicRun(functionName) {
picChange(1);
interval = setInterval(PicNext, "3000");
}
$(document).ready(function () {
PicRun();
});
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " <html xmlns=" <head>
<title>圖片切換</title>
<script src="jquery-1.8.0.js" type="text/javascript"></script>
<link href="picchange.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="picMain">
<div class="picimg" id="divImg">
<img src="images/pic1.jpg" class="pic" />
<img src="images/pic2.jpg" class="pic" />
<img src="images/pic3.jpg" class="pic" />
<img src="images/pic4.jpg" class="pic" />
<img src="images/pic5.jpg" class="pic" />
<img src="images/pic6.jpg" class="pic" />
<img src="images/pic7.jpg" class="pic" />
<img src="images/pic8.jpg" class="pic" />
</div>
<div class="picaction" id="divLink">
<a href="images/pic8.jpg" title="8" onclick=" return picChange(8)" class="">8</a> <a href="images/pic7.jpg" title="7" onclick=" return picChange(7)">7</a> <a href="images/pic6.jpg" title="6"
onclick=" return picChange(6)">6</a> <a href="images/pic5.jpg" title="5" onclick=" return picChange(5)">
5</a> <a href="images/pic4.jpg" title="4" onclick=" return picChange(4)">4</a>
<a href="images/pic3.jpg" title="3" onclick=" return picChange(3)">3</a> <a href="images/pic2.jpg"
title="2" onclick=" return picChange(2)">2</a> <a href="images/pic1.jpg" title="1"
onclick=" return picChange(1)" class="">1</a>
</div>
<div id="picremark" class="picRemark">
測(cè)試介紹文件了啊</div>
</div>
</body>
</html>
css的實(shí)現(xiàn)
.picMain
{
margin: auto;
overflow: hidden;
width: 1000px;
height: 400px;
position: relative;
}
.picimg
{
width: 10000px;
height: 400px;
background-color: #000000;
position: absolute;
top: 0px;
}
.picRemark
{
position: absolute;
width: 500px;
height: 50px;
bottom: 0px;
left: 0px;
color: #FFFFFF;
text-indent: 2em;
}
.picRemark a
{
color: #FFFFFF;
text-decoration: none;
}
.picRemark a:hover
{
text-decoration: underline;
}
.picaction
{
position: absolute;
width: 1000px;
height: 50px;
background-color: #000000;
filter: alpha(opacity=50);
-moz-opacity: 0.5;
opacity: 0.5;
overflow: auto;
bottom: 0px;
left: 0px;
text-align: right;
}
.picaction a
{
border: 1px solid #C0C0C0;
width: 30px;
height: 30px;
float: right;
line-height: 30px;
text-decoration: none;
text-align: center;
color: #FFFFFF;
font-weight: bold;
margin-top: 10px;
display: block;
margin-right: 10px;
}
.pic
{
width: 1000px;
height: 400px;
float: left;
}
.picselect
{
background-color: #919191;
}
以上就是本文的全部?jī)?nèi)容了,實(shí)現(xiàn)的功能很實(shí)用,希望大家能夠喜歡。
相關(guān)文章
jQuery中delegate和on的用法與區(qū)別詳細(xì)解析
本篇文章主要是對(duì)jQuery中delegate和on的用法與區(qū)別進(jìn)行了詳細(xì)的介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-01-01jQuery Validate表單驗(yàn)證深入學(xué)習(xí)
這篇文章主要介紹了jQuery Validate表單驗(yàn)證入門知識(shí),該插件捆綁了一套有用的驗(yàn)證方法,包括 URL 和電子郵件驗(yàn)證,同時(shí)提供了一個(gè)用來(lái)編寫用戶自定義方法的 API,感興趣的小伙伴們可以參考一下2015-12-12jQuery在header中設(shè)置請(qǐng)求信息的方法
這篇文章主要介紹了jQuery在header中設(shè)置請(qǐng)求信息的方法,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-03-03jquery.fileEveryWhere.js 一個(gè)跨瀏覽器的file顯示插件
大牛ppk都說(shuō)過(guò),在從多表單控件中,上傳文件控件的樣式是最難以控制的。見文章Styling an input type="file"。本插件也多是參考此文2011-10-10基于jQuery實(shí)現(xiàn)的美觀星級(jí)評(píng)論打分組件代碼
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)的美觀星級(jí)評(píng)論打分組件代碼,涉及jQuery回調(diào)函數(shù)及頁(yè)面元素屬性動(dòng)態(tài)操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10jQuery基礎(chǔ)的工廠函數(shù)以及定時(shí)器的經(jīng)典實(shí)例分析
下面小編就為大家?guī)?lái)一篇jQuery基礎(chǔ)的工廠函數(shù)以及定時(shí)器的經(jīng)典實(shí)例分析。小編覺得挺不錯(cuò)的,現(xiàn)在2016-05-05