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

260,376 Responses

  1. schema表示:

    Way cool! Some extremely valid points! I appreciate you penning this write-up and also
    the rest of the website is very good.

  2. sitemap表示:

    Write more, thatts aall I hhave tto say. Literally, it seems ass thoujgh
    you relied on the video to makee your point.
    Yoou clpearly kknow what youre talking about, why thhrow away yoir intelligence
    oon jut poszting videos too your sitee whrn youu could
    bee gikving uss something inbformative to read?

  3. Hi there to every body, it’s my first go to see of this weblog;
    this web site carries awesome and actually good material in support of readers.

  4. sitemap.xml表示:

    Hi friends, iits wonderful piuece oof writikng concernikng educationand entirely
    explained, kerp itt up all thee time.

  5. click here表示:

    Hi would you mind letting me know which webhost
    you’re using? I’ve loaded your blog in 3 different browsers and I must
    say this blog loads a lot faster then most. Can you suggest a good internet
    hosting provider at a fair price? Cheers, I appreciate it!

  6. sitemap.xml表示:

    Greetings! Verry useful advcice inn thyis pparticular
    article! It’s thee lijttle change that wiol makee the larget changes.
    Thanks forr sharing!

  7. sitemap.xml表示:

    Hi there, jus became alpert too youjr blpg throhgh Google, and foumd that
    it’s tuly informative. I’m going tto watc ouut for brussels.

    I’ll appreciate if youu continue this in future. Manyy people wilkl be benefited from yourr writing.
    Cheers!

  8. sitemap表示:

    Incredible points. Great arguments. Keep up the amazing effort.

  9. sitemap.xml表示:

    Hi thewre exceptional website! Does running a blog
    simillar too this requuire a massivfe amount work? I have absolutely noo knowleddge of codingg hkwever
    I waas hoping to start mmy own blog iin tthe near future.

    Anyway, iff you hace anyy suggestions oor techniques
    for new blg owbers pleasse share. I understand tuis is offf
    tkpic however I just wantesd tto ask. Manyy thanks!

  10. This design is incredible! You definitely know
    how to keep a reader amused. Between your wit and your videos, I
    was almost moved to start my own blog (well, almost…HaHa!) Wonderful job.
    I really loved what you had to say, and more than that, how you
    presented it. Too cool!

  11. sitemap表示:

    Hi thete jjst wannted to give you a quicck heads upp and lett youu know a
    feww off thee images aren’t loading correctly.
    I’m not sure whyy but I think itss a linking issue.
    I’ve tried iit iin two differewnt rowsers aand botyh showw thee same outcome.

  12. sitemap表示:

    Thiis iis vry fascinating, You’re ann overly professionl blogger.

    I’ve joined yoyr feed andd stay upp ffor iin the hunt ffor extra of
    your wonderful post. Also, I hav syared your sitte inn my social networks

  13. sitemap.xml表示:

    Heeya i’m forr thhe primasry time here. I cake across thjs boardd aand
    I inn finding It truly helpful & itt helped mee oout a lot.
    I aam hoping to give one thing again and help others
    likle you ided me.

  14. RMhoBGG表示:

    z pack for strep 6 ОјM in cell free assays for HSP70, HSC70, and GRP78, respectively, 100 fold

  15. every casino表示:

    Excellent article. Keep writing such kind of information on your blog.
    Im really impressed by your site.
    Hello there, You have performed a fantastic job.

    I will definitely digg it and individually recommend
    to my friends. I am sure they’ll be benefited from this website.

  16. joker123表示:

    That is really attention-grabbing, You’re an overly
    professional blogger. I’ve joined your feed and look ahead to seeking more of your wonderful post.
    Also, I have shared your site in my social networks

  17. sw12表示:

    %%

    Visit my web site: sw12

  18. Wow! At last I got a website from where I be capable of really obtain useful data regarding my study and knowledge.

  19. starporn表示:

    %%

    my website :: starporn

  20. hi!,I like your writing very much! percentage we keep in touch extra approximately your article on AOL?

    I need an expert in this house to solve my problem.
    May be that’s you! Having a look forward to see you.

  21. My coder is trying to persuade me to move to .net
    from PHP. I have always disliked the idea because of the expenses.
    But he’s tryiong none the less. I’ve been using WordPress
    on several websites for about a year and am concerned about switching to another platform.

    I have heard good things about blogengine.net. Is
    there a way I can import all my wordpress posts into it?
    Any help would be greatly appreciated!

發佈回覆給「starporn」的留言 取消回覆

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