国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Jquery 實現圖片輪換

2024-05-06 16:15:24
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了Jquery 實現圖片輪換,雖然還有點小問題,但是影響不大,還是推薦給大家,需要的朋友可以參考下
 

網站首頁沒有一點動畫怎么可以,我以前用過Flash As3做過圖片切換,效果非常不錯,可是麻煩,改變起來麻煩。一直都想自己做個圖片切換效果,總認為比較麻煩,今天自己實踐了一下,其實還比較簡單。不過有個小問題,IE8不兼容模式下 設置有透明效果的div 樣式添加失效了,但是我用谷歌,IE8兼容測試都ok。

反正是給自己記錄的,也不多話了,js沒有與頁面分離,也沒有做出插件。一個網站要不了幾個這種效果,先實現了再說吧。最后的效果還是很高大上的。

頁面+JS代碼

 

復制代碼代碼如下:

<script type="text/javascript">
        var picCurrent = 1;
        var picTotal = 8;
        var interval; //自動運行
        function picChange(current) {
            //停止當前動畫
            if ($("#divImg").is(":animated")) { $("#divImg").stop(); }
            picCurrent = current;
            //為當前選擇的設置樣式
            $("#divLink").find("a").removeClass("picselect")
            $("#divLink").find("a[title='" + picCurrent + "']").addClass("picselect");
            //設置下面的圖片說明
            var remark = "<a href=/"images/pic" + picCurrent + ".jpg/">";
            switch (picCurrent) {
                case 1: remark += " 菊花〔拉丁學名:Dendranthema morifolium(Ramat. )Tzvel.〕,常用chrysanthemum。菊花是菊科,菊屬多年生草本... "; break;
                default: remark += picCurrent + "測試說明"; break;
            }
            remark += "</a>";
            $("#picremark").html(remark);
            //運行動畫
            $("#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);
        }
        //自動切換圖片
        function PicRun(functionName) {
            picChange(1);
            interval = setInterval(PicNext, "3000");
        }
        $(document).ready(function () {
            PicRun();
        });
    </script>

 
復制代碼代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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" style="border-left-color: rgb(0, 153, 204); border-left-width: 1px; border-left-style: solid; padding: 0px 3px; margin: 3px auto 0px; width: 640px; background-color: rgb(242, 246, 251); clear: both; border-top-color: rgb(0, 153, 204); border-top-width: 1px; border-top-style: solid; border-right-color: rgb(0, 153, 204); border-right-width: 1px; border-right-style: solid;"> 復制代碼代碼如下:

.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;
}

 

以上就是本文的全部內容了,實現的功能很實用,希望大家能夠喜歡。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 新源县| 麻江县| 青铜峡市| 滨海县| 岑溪市| 恩施市| 禄丰县| 汶上县| 子洲县| 石家庄市| 越西县| 巩留县| 阜新市| 乌拉特后旗| 双牌县| 垦利县| 天峨县| 瑞金市| 余庆县| 观塘区| 宜宾县| 甘南县| 苗栗市| 海兴县| 凯里市| 禄劝| 平度市| 施甸县| 双鸭山市| 彰化县| 土默特左旗| 岚皋县| 英德市| 贺兰县| 镇安县| 菏泽市| 印江| 丰镇市| 安远县| 保山市| 佳木斯市|