JQuery大圖輪播

來源:互聯網
上載者:User

標籤:end   技術分享   onclick   auto   class   weight   city   center   rip   

第一步建立一個js檔案夾將現有的jquery-1.7.1.min.js放到該檔案夾下引如到head部分

第二步封裝一個jS指令碼方法引入到頁面的HEAD部分,代碼如下:

 1 function myalert(t, c, tc) { 2  3     var tcstr = "<div id=\"tc\" style=\"position: fixed; width: 400px; left: 50%; margin-left: -200px; top: -500px; border: 1px solid red; box-shadow: 0 0 10px pink; z-index: 1001; background-color: white;\">"; 4     tcstr += "<div id=\"tc-top\" style=\"width: 100%; height: 30px; background-color: red; color: white; font-size: 18px; font-weight: bold; text-align: center; line-height: 30px;\">"; 5     tcstr += t;//這裡是標題 6     tcstr += "</div><div id=\"tc-main\" style=\"padding: 20px; text-align: center;\">"; 7     tcstr += c; 8     tcstr += "</div><div id=\"tc-bottom\" style=\"position: relative; width: 100%; height: 40px;\">"; 9     tcstr += "<div onclick=\"tcbtn1();\" id=\"tc-btn1\" style=\"position: absolute; top: 5px; left: 50%; margin-left: -50px; width: 100px; height: 30px; background-color: pink; color: white; text-align: center; line-height: 30px; cursor: pointer;\">確定</div></div></div>";10     tcstr += "<div id=\"tc-zz\" style=\"position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; background-color: black; opacity: 0.3; display: none; z-index: 1000;\"></div>";11 12     $(document.body).append(tcstr);13 14     $("#tc-top").text(t);15     $("#tc-main").html(c);16     $("#tc").animate({ top: "100" }, 500).animate({ top: "90" }, 100).animate({ top: "100" }, 200);17     $("#tc-zz").css("display", "block");18     if (tc != null) $("#tc-top").css("background-color", tc);19 }20 21 function tcbtn1() {22     $("#tc").animate({ top: "110" }, 200).animate({ top: "-500" }, 500, function () {23         $("#tc-zz").css("display", "none");24         $("#tc").remove();25         $("#tc-zz").remove();26     });27 }
js指令碼方法


第二步建立一個web表單;該表單的HTML代碼和JQuery代碼如下如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="datulunbo.aspx.cs" Inherits="datulunbo" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <script src="js/jquery-1.7.1.min.js"></script>    <title></title>    <style type="text/css">        #dt {            margin-top: 50px;            margin: 0 auto;            width: 800px;            height: 400px;            border: 2px solid black;            overflow: hidden;        }        #dt-items {            position: relative;            width: 8000px;            height: 400px;            z-index: 10;        }        .dt-item {            width: 800px;            height: 400px;            float: left;            background-size: 100%;        }        .btn {            position: relative;            top: -400px;            width: 50%;            height: 100%;            float: left;            z-index: 11;        }    </style></head><body>    <form id="form1" runat="server">        <div id="dt">            <div id="dt-items">                <div class="dt-item" style="background-image: url(images/1.jpg);"></div>                <div class="dt-item" style="background-image: url(images/2.jpg);"></div>                <div class="dt-item" style="background-image: url(images/3.jpg);"></div>                <div class="dt-item" style="background-image: url(images/4.jpg);"></div>                <div class="dt-item" style="background-image: url(images/5.jpg);"></div>                <div class="dt-item" style="background-image: url(images/6.jpg);"></div>            </div>            <div id="btn_left" class="btn"></div>            <div id="btn_right" class="btn"></div>        </div>    </form></body></html><script type="text/javascript">    var imgindex = 0;    var timer;    $("#btn_left").click(function () {        imgindex--;        if (imgindex < 0) imgindex = $(".dt-item").length - 1;        var imgleft = parseInt("-" + parseInt($(".dt-item").eq(0).width()) * imgindex);        $("#dt-items").stop().animate({ left: imgleft }, 500);    });    $("#btn_right").click(function () {        imgindex++;        if (imgindex > ($(".dt-item").length - 1)) imgindex = 0;        var imgleft = parseInt("-" + parseInt($(".dt-item").eq(0).width()) * imgindex);        $("#dt-items").stop().animate({ left: imgleft }, 500);    });    timer = automove();    function automove() {        return window.setInterval(function () {            imgindex++;            if (imgindex > ($(".dt-item").length - 1)) imgindex = 0;            var imgleft = parseInt("-" + parseInt($(".dt-item").eq(0).width()) * imgindex);            $("#dt-items").stop().animate({ left: imgleft }, 500);        }, 2000);    }    $("#dt").hover(function () {        window.clearInterval(timer);    }, function () {        timer = automove();    });</script>
View Code

 

JQuery大圖輪播

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.