利用TweenMax針對HTML頁面製作動畫 – jQuery Mobile篇

在Dreamweaver5.5之後多了一個jQuery Mobile面板,主要是利用jQuery來製作一些行動裝置的元素,接下來這篇文章就利用Dreamweaver提供的幾項元素加上TweenMax來製作手機動畫頁面。

因為這篇文章應用到的動畫功能,依舊和前兩篇差不多,所以就直接看範例吧!首先,第一個範例是利用「jQuery 翻轉切換開關」來控制動畫的播放,除了可以從前面的連結看到這個範例之外,也因為這是特別針對行動裝置所設計的案例,大家也可以在手機輸入「goo.gl/LofiK」網址來觀賞,下面是本範例整個網頁的程式碼:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalabke=no, width=device-width" />
    <title>貓咪欣賞</title>
    <link href="jquery-mobile/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css">
    <script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script src="jquery-mobile/jquery.mobile-1.0.min.js" type="text/javascript"></script>
    <script src="src/minified/TweenMax.min.js"></script>
    <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
        }

        #photo {
            text-align: center;
        }

        #selector {
            text-align: center;
            width: 50%;
            margin-left: auto;
            margin-right: auto;
        }
    </style>
    <script language="javascript">
        var playNo = 1; /* 定義目前播放張數變數 */
        function photoPlay() {
            var controler = document.getElementById("flipswitch");
            if (controler.options[controler.selectedIndex].value == "on") {
                clock = setInterval(timer, 5000);
            } else {
                clearInterval(clock);
            } /* 設定每五秒執行timer函數 */
            function timer() {
                var pic = document.getElementById("photo"); /* 利用pic紀錄畫面中ID為photo的元素 */
                playNo++; /* 增加張數 */
                if (playNo > 19) {
                    playNo = 1;
                } /* 設定超過圖片張數後從頭播放 */
                TweenMax.to(pic, 1, {
                    css: {
                        alpha: 0
                    },
                    ease: Expo.easeIn,
                    onComplete: function () {
                        pic.innerHTML = "<img src=photo/photo" + playNo + ".jpg width=300 height=200>";
                        TweenMax.to(pic, 1, {
                            css: {
                                alpha: 1
                            },
                            ease: Expo.easeOut
                        });
                    }
                });
            }
        }
    </script>
</head>
<body onLoad="photoPlay()">
    <div data-role="page" id="page">
        <div data-role="header">
            <h1>貓咪欣賞</h1>
        </div>
        <div data-role="content">
            <div id="photo"><img src="photo/photo1.jpg"></div>
            <div data-role="fieldcontain" id="selector"> <select name="flipswitch" id="flipswitch"
                    onChange="photoPlay()" data-role="slider">
                    <option value="off">關閉</option>
                    <option value="on" selected>開啟</option>
                </select> </div>
        </div>
        <div data-role="footer">
            <h4>©2012 Copyright Stanley Ma Cloud Research.</h4>
        </div>
    </div>
</body>
</html>

接下來的第二個範例在程式上面會比較複雜,因為想要加強上一個範例的互動性,所以在同樣的範例上面增加「上一張」、「下一張」與「播放控制」的功能,可在手機輸入「goo.gl/GyAVt」網址觀賞,如果你仔細看的話,會發現這個範例中呼叫網頁元素的語法有改變,其實既然是利用jQuery來製作,本來就可以利用jQuery所提供呼叫網頁元素的指令來製作會比較方便,總之是因為有了下面這行語法,才可以利用這種方式來呼叫的喔!

<script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>

下面是本範例整個網頁的程式碼:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalabke=no, width=device-width" />
    <title>貓咪欣賞</title>
    <style type="text/css">
        * {
            margin: 0px;
            padding: 0px;
        }

        #photo {
            text-align: center;
        }

        #selector {
            text-align: center;
            width: 50%;
            margin-left: auto;
            margin-right: auto;
        }

        #count {
            text-align: center;
            width: 50%;
            margin-left: auto;
            margin-right: auto;
            font-size: 12px;
        }
    </style>
    <link href="jquery-mobile/jquery.mobile-1.0.min.css" rel="stylesheet" type="text/css">
    <script src="jquery-mobile/jquery-1.6.4.min.js" type="text/javascript"></script>
    <script src="jquery-mobile/jquery.mobile-1.0.min.js" type="text/javascript"></script>
    <script src="src/minified/TweenMax.min.js"></script>
    <script language="javascript">
        var playing = 1; /* 偵測目前是否為播放中的變數(1為播放0為暫停) */
        var playNo = 1; /* 定義目前播放張數變數 */ /* 執行計時器 */
        function photoPlay() {
            clock = setInterval(timer, 5000);
        } /* 計時執行函數 */
        function timer() {
            playNo++; /* 增加張數 */
            checkPlayNo() /* 呼叫檢查張數是否有誤的函數 */ photoSlide(); /* 呼叫動畫切換照片的函數 */
        } /* 動畫切換照片的函數 */
        function photoSlide() {
            var pic = $("#photo"); /* 利用pic紀錄畫面中ID為photo的元素 */
            TweenMax.to(pic, 0.5, {
                css: {
                    alpha: 0
                },
                ease: Expo.easeIn,
                onComplete: function () {
                    pic.html("<img src=photo/photo" + playNo + ".jpg width=300 height=200>");
                    TweenMax.to(pic, 1, {
                        css: {
                            alpha: 1
                        },
                        ease: Expo.easeOut
                    });
                }
            });
            $("#count").html(playNo + " / 19"); /* 更換顯示張數的文字 */
        } /* 檢查張數是否有誤的函數 */
        function checkPlayNo() {
            if (playNo > 19) {
                playNo = 1;
            } else if (playNo < 1) {
                playNo = 19;
            }
        } /* 前往上一張的函數 */
        function prevFn() {
            clearInterval(clock);
            playNo--;
            checkPlayNo() photoSlide();
            photoPlay();
        } /* 前往下一張的函數 */
        function nextFn() {
            clearInterval(clock);
            playNo++;
            checkPlayNo() photoSlide();
            photoPlay();
        } /* 播放控制函數 */
        function controlFn() {
            if (playing == 1) {
                playing = 0;
                $("#controlBtn").html("播放") clearInterval(clock);
            } else if (playing == 0) {
                playing = 1;
                $("#controlBtn").html("暫停") clock = setInterval(timer, 5000);
            }
        }
    </script>
</head>
<body onLoad="photoPlay()">
    <div data-role="page" id="page">
        <div data-role="header">
            <h1>貓咪欣賞</h1>
        </div>
        <div data-role="content">
            <div id="photo"><img src="photo/photo1.jpg"></div>
            <div data-role="controlgroup" data-type="horizontal" id="selector"><a href="#" data-role="button"
                    id="prevBtn" onClick="prevFn()">上一張</a><a href="#" data-role="button" onClick="controlFn()"><label
                        id="controlBtn">暫停</label></a><a href="#" data-role="button" onClick="nextFn()">下一張</a></div>
            <div id="count">1 / 19</div>
        </div>
        <div data-role="footer">
            <h4>©2012 Copyright Stanley Ma Cloud Research.</h4>
        </div>
    </div>
</body>
</html>

希望大家看過這幾篇「利用TweenMax針對HTML頁面製作動畫」的範例之後,可以更順利的創作出自己的網頁。

You may also like...

194,984 Responses

  1. CashUSA.com is a great resource to find payday loans online.
    There are many options for you to get a loan. Before you submit an online
    application, here are some things you should know.
    The repayment terms can range from six months to seven years.

  2. While this type of loan is convenient however, it can be harmful for those with lower incomes.
    Many people are unable to pay back these uk payday Loans
    and end up in the cycle of debt.

  3. An online Payday Loan loan site allows you to communicate information about your present situation with network of lenders.

    Multiple lenders are able to review the loan request
    and explain their conditions. You may choose to accept one or more.

  4. Paydayloan Uk表示:

    Payday loans offer many advantages however, they might not be the best choice for everyone.
    First of all, they’re expensive when compared with other types of borrowing.
    This type of loan is not offered to those with poor credit scores.

    Feel free to visit my page; Paydayloan Uk

  5. If you’re in dire need of money quickly, you may be wondering how you can get cash via a paydayloan Paydayloans Online.
    The process is straightforward and can be completed in less than five minutes.

  6. It is possible to take the payday uk loans (sharingstillness.com)
    uk loan option if you are facing an emergency. These short-term
    loans have high interest rates, however they’re designed
    to help people who are in a crisis.

  7. A popular method of taking CBD is in capsule form. It is an easy, discreet, and cheap way to consume cannabis.
    The Best Cbd capsules part about CBD capsules is that they don’t leave oil stains or an unpleasant taste.

  8. Data Hk表示:

    There are several ways of getting the results of the Togel Data Hk game.
    These are prediksi keluaran, hasil angka, Bocoran togel hk hari ini, and keluaran sgp hk hari ini.

  9. Toto Hk表示:

    There are many ways to get the results of the Togel HK Game.

    These are prediksi keluaran, hasil angka, Bocoran togel Toto Hk hari ini, and keluaran sgp hk hari ini.

  10. There are a myriad of online payday loans sources for a payday loan. This article will examine the benefits and drawbacks of various choices.

    It also includes customer reviews, the conditions for qualifying, Rates, and Fees.

  11. The data pengeluaran HK hari ini wajib digunakan para
    pemain untuk menebak hasil keluaran togel hongkong hari ini.
    This data is comprehensive and provides valuable information for players and
    referees.

  12. The data pengeluaran HK hari ini wajib digunakan para pemain untuk menebak hasil keluaran togel hongkong hari ini.
    This data is complete and provides valuable information for referees and players.

  13. Are you thinking about applying for payday loans?
    These short-term loans are monitored by the Financial Conduct Authority.

    Learn more about this form of consumer credit. Here are some of the benefits of applying for
    a payday loan uk loan:

  14. Shantae表示:

    If you’re considering applying for an online payday pay day loan online – Shantae – it is recommended to be aware of your options prior to signing on the signature line.
    Rates, repayment options, and the lender’s reputation are all crucial
    factors to consider.

  15. If you need to repair your cracked window, call an expert in window repair Window.Repair Near Me
    me. These professionals have the tools and experience to repair
    holes or cracks in windows.

  16. dauzbdsi表示:

    https://erythromycin1m.com/# what type of drug is erythromycin

  17. It is actually a great and helpful piece of information. I am
    satisfied that you shared this useful info with us. Please keep us up to date like this.
    Thank you for sharing.

  18. Slonmob表示:

    xp8tz

    v7prd

    lok5

  19. simgdzuf表示:

    erythromycin eye ointment uses for erythromycin

  20. Slonmob表示:

    3tehp

    4fitj

    724g

  21. Slonmob表示:

    kyaya

    r1cug

    2v0c

  22. Slonmob表示:

    xyohx

    oavn3

    whbe

  23. mgtircvj表示:

    erythromycin ophthalmic ointment https://erythromycin1m.com/#

  24. click here表示:

    Hey there excellent blog! Does running a blog such as
    this require a great deal of work? I’ve no understanding of computer programming however I had been hoping to start my own blog in the near future.
    Anyways, if you have any recommendations or techniques for new
    blog owners please share. I understand this is off subject
    but I simply had to ask. Thanks a lot!

    Also visit my web site; click here

  25. y2mate表示:

    This is the wave – the big wave.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。