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

192,972 Responses

  1. muxzozfn表示:

    buy provigil 100mg generic modafinil 200mg for sale

  2. MichaelPlela表示:

    price of cialis 20 mg cialis from india tadalafil without a doctor’s prescription

  3. linrdxfe表示:

    modafinil 200mg canada provigil cost

  4. viwxikaf表示:

    provigil 200mg drug modafinil 100mg uk order modafinil 200mg without prescription

  5. MichaelPlela表示:

    cialis from india tadalafil tablets 20 mg india cialis pills

  6. MichaelPlela表示:

    clomid clomid for sale canada clomid tablets

  7. isosrjyy表示:

    provigil 100mg uk oral modafinil 200mg

  8. rvgmmtsl表示:

    order provigil sale buy modafinil online provigil generic

  9. btanqesg表示:

    modafinil tablet generic provigil generic modafinil

  10. MichaelPlela表示:

    best price for daily cialis cialis pharmacy cialis

  11. ranthro表示:

    IncrediMail Password Decryptor also comes with a comprehensive help file that will be very usefull for all beginners.The program is completely safe and compatible with both 32- and 64-bit systems.{
    “iisSettings”: {
    “windowsAuthentication”: false,
    “anonymousAuthentication”: true,
    “iisExpress”: {
    “applicationUrl”: ” https://pimspadddansthe.weebly.com

    6add127376 ranthro

  12. burtmanr表示:

    The interface is very neat, letting you import the files while keeping you posted on the extraction process. The selection algorithm works really well, and while it worked well on our samples, I wouldn’t be surprised to see him get the more complex drawing files that we tried our hands at.
    A real-life application which transforms drawings from one format into another.

    Data entry is easier, faster and easier than ever

    The common computer keyboard has become somewhat of a relic for devices https://cse.google.ro/url?sa=t&url=https://liabarera.weebly.com

    6add127376 burtmanr

  13. quibro表示:

    So, if you’re looking for an app that aims to help you learn rhythmic music production, you should definitely go for Liquid Rhythm.

    Features:

    – It has over 300+ independent instruments and instruments packs.
    – You can drag and drop the instruments to the Arranger.
    – Some of the instruments (bass, keys, brass) comes with some preset sounds.
    – Solo effect and volume control for the instruments.
    – You can assign global shortcuts https://eswalilreu.weebly.com

    6add127376 quibro

  14. dekogra表示:

    It’s a great tool for anyone who likes hard disks.

    Figure 1. Drive Health report

    2) PPSPlus v10
    This installer package includes the most popular productivity and entertainment software that you do not already have installed, such as Office 2013 Pro Plus, Adobe Photoshop CS5, Adobe InDesign CS5 and more!
    PPSPlus gives you the freedom to enjoy previously packaged software that you have purchased or downloaded from various online software distributors. You can either view or search http://www.5yemao.com/wp-content/themes/begin/inc/go.php?url=https://enripeven.weebly.com

    6add127376 dekogra

  15. janndesi表示:

    Pros: Ability to display and refresh the current public IP address and host name without adding entries to the Windows Registry, as well as copy and paste the information to the clipboard when required.
    Cons: Not updated for a long time and no support for later Windows versions.1. Field of the Invention
    The present invention relates to a fixture that can be used to simulate the real lighting condition for a particular situation during photography or filming, and particularly a lighting fixture simulating natural light. https://sohabiri.weebly.com

    6add127376 janndesi

  16. henrjam表示:

    A free version of School PC is only supported for personal use; a commercial version is also available that enables remote controlled computers, contact with multiple computers, a dashboard and reports. It can also be deployed on multiple computers and limit the maximum number of allowed connections.
    Stream the activity
    As monitoring software for schools, School PC generates an event log that you can interact with via the Manage It interface. Even using a browser, you can assign a readable name to each logged event, which makes https://biomilrori.weebly.com

    6add127376 henrjam

  17. MichaelPlela表示:

    sildenafil 20 mg sildenafil viagra tablets for men

  18. Attractive section of content. I just stumbled upon your web
    site and in accession capital to assert that I acquire in fact enjoyed account your blog posts.
    Anyway I will be subscribing to your feeds and even I achievement you access consistently fast.

  19. radlav表示:

    Grupo BMG is a Latin music veteran that has kept the genre alive for decades. With over hundred years of history, the British company Grupo BMG is known for great quality music by popular and emerging artists. Their extensive music catalog includes Latin music, as well as some Spanish pop tunes and many more.

    There’s a straightforward interface that displays all the information you need from a single page with a clear layout. The options are divided into radio, portal, videos http://kadett-club.by/forum/away.php?s=https://prestaidevi.weebly.com

    6add127376 radlav

發佈留言

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