利用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...

236,703 Responses

  1. The 10 Most Scariest Things About Retro Fridge Freezer Sale retro fridge freezer sale

  2. installation表示:

    An Adventure Back In Time A Conversation With People About
    Double Glazing Windows Repairs 20 Years Ago installation

  3. Key bmw表示:

    See What Replacement Key Bmw Tricks The Celebs Are Using Key bmw

  4. 10 Methods To Build Your ADHD Diagnosis Empire Get diagnosed with add

  5. How To Make An Amazing Instagram Video About Railroad Injuries Legal danville railroad crossing accident lawyer [https://Candays.com]

  6. 10 Things We All Are Hating About Bi-Fold Door Repair bi-fold door Repairs Near me

  7. Hoover Fridge Freezer With Water Dispenser Is The Next Hot Thing In Hoover
    Fridge Freezer With Water Dispenser integrated fridge freezer with water ice dispenser

  8. You’ll Be Unable To Guess 4 Wheel Disability Scooter’s Tricks 4 Wheel Disability Scooter; Web018.Dmonster.Kr,

  9. 20 Resources That Will Make You More Successful At Electric Powered Wheelchair electric Powered wheelchairs

  10. 15 Things Your Boss Wished You Knew About G Spot Toy
    g-Spot Stimulators (mozillabd.science)

  11. Nine Things That Your Parent Teach You About 4 Wheel Rollator With Seat 4 wheel rollator with Seat

  12. Zack Foxworth表示:

    Technology Is Making Best Folding Treadmill Small Space Better Or
    Worse? Zack Foxworth

  13. You’ll Never Be Able To Figure Out This Automatically Folding Mobility Scooter’s Benefits Automatically Folding Mobility Scooter

  14. Veleco Uk 10 Things I’d Loved To Know Earlier veleco Website

  15. Togel4d表示:

    9 . What Your Parents Teach You About Togel4d Togel4d

  16. plise perde表示:

    plise perde | Yazınız, plise perdelerin ticari mekanlarda nasıl bir marka kimliği oluşturabileceğini örneklerle anlatıyor. İş yerlerinde marka renklerini ve logolarını plise perdeler üzerinde nasıl kullanabileceğinizi gösteren öneriler, kurumsal kimlik yaratmada etkili bir yol sunuyor.

  17. Guide To Walking Rollator: The Intermediate Guide Towards Walking Rollator Walking rollator

  18. See What Integrated Fridge Freezer Tricks The Celebs Are Using integrated
    fridge freezer (forum.Elaivizh.eu)

  19. Drstobeese表示:

    online viagra us pharmacy: apollo pharmacy online – provigil online pharmacy

  20. Drstobeese表示:

    cialis thailand pharmacy: inhouse pharmacy dutasteride – lexapro pharmacy assistance

  21. 12 Companies Leading The Way In Cleaning Robot Mop And Vacuum Cleaning Robots

  22. What’s The Job Market For 3 Wheel Aluminum Rollator Professionals Like?
    3 Wheel Aluminum Rollator

  23. Если вы искали где отремонтировать сломаную технику, обратите внимание – сервисный центр в краснодаре

  24. 10 Facts About Car Boot Scooter That Will Instantly Put
    You In A Good Mood folding mobility scooters for Car boot

  25. Профессиональный сервисный центр по ремонту планшетов в Москве.
    Мы предлагаем: ремонт планшетов на дому
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  26. What’s The Job Market For G Spot Vibrater Professionals?
    G Spot Vibrater

  27. Shanel表示:

    Guide To Pavement Mobility Scooters With Suspension: The Intermediate Guide The
    Steps To Pavement Mobility Scooters With Suspension pavement mobility scooters with
    suspension (Shanel)

  28. 10 Facts About 3 Wheel Lightweight Mobility Scooters That
    Will Instantly Bring You To A Happy Mood 3 Wheel Electric Scooters

  29. Quiko表示:

    Buy Sell Rent Anything online in India
    https://quiko.in/

發佈留言

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