利用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,887 Responses

  1. bundatoto表示:

    I’m extremely impressed with your writing skills as well as with the
    layout on your blog. Is this a paid theme or did you modify it yourself?

    Anyway keep up the excellent quality writing, it
    is rare to see a nice blog like this one today.

  2. sitemap.xml表示:

    Hi, I do believe thgis is ann excellent website. I stumbledupon itt
    😉 I mmay rebisit yet again sinhce i have book marked it.

    Mobey and freedomm is the best way to change, maay yoou be rich and continue too hepp others.

  3. Otuslot表示:

    Please let me know if you’re looking for a writer for your weblog.

    You have some really great articles and I believe I would be a good
    asset. If you ever want to take some of the load off, I’d really like to write some articles for your
    blog in exchange for a link back to mine. Please blast me an e-mail if interested.
    Regards!

  4. sitemap表示:

    Goood article. I certainly apprreciate thiss website.
    Keep writing!

  5. lembu4D表示:

    I blog often and I really appreciate your information.
    The article has truly peaked my interest. I’m going to take a note of
    your website and keep checking for new details about once a week.
    I subscribed to your RSS feed as well.

  6. Ara表示:

    It’s a pity you don’t have a donate button! I’d certainly
    donate to this outstanding blog! I suppose for now i’ll settle
    for book-marking and adding your RSS feed to my Google account.
    I look forward to new updates and will talk about this website with
    my Facebook group. Talk soon!

  7. Your experience shines via Evidently. I trust your insights.

  8. Your skills shines by means of Evidently. I have confidence in your insights.

  9. Your producing adds a great deal of worth to the online Neighborhood. Thank you! https://businessmarketnews.uk/best-roofing-companies-in-oshawa/

  10. The worth you provide free of charge is extraordinary. I might pay for this! https://www.hituponviews.com/best-roofing-companies-in-oshawa/

  11. Your blog site is my go-to resource for being up-to-day With this discipline.

  12. I really like how you resolved common misconceptions in this put up. It is important to set the history straight on these difficulties.

  13. I go to see every day some blogs and websites to read posts, however this weblog
    offers feature based writing.

  14. I’m often enthusiastic to check out a completely new put up from you in my feed.

  15. boobs表示:

    I’m not sure why but this website is loading very slow for me.
    Is anyone else having this problem or is it a issue
    on my end? I’ll check back later and see if the problem still exists.

  16. You ought to be a part of a contest for one of the greatest sites online.
    I most certainly will highly recommend this website!

  17. Your material has this magical capacity to make me really feel smarter immediately after looking through.

  18. This piece of writing is in fact a good one it helps new web users, who are wishing in favor of blogging.

  19. Hello! Do you know if they make any plugins to help with SEO?
    I’m trying to get my blog to rank for some targeted keywords
    but I’m not seeing very good success. If you know of any please share.

    Appreciate it! You can read similar blog here: Dobry sklep

  20. Your web site warrants all the recognition for the worth it adds to visitors’ life.

  21. metabofix表示:

    Greetings! Very useful advice in this particular article!
    It’s the little changes that produce the most important changes.

    Many thanks for sharing!

  22. I’m amazed with the depth of your respective awareness on this matter. You Obviously did your study.

  23. The 10 Most Scariest Things About Porn Star british porn Star

  24. Evime Venster Systems’in pileli sinekliklerinden birini taktırdım ve gerçekten çok memnunum. Kaliteli malzeme ve kolay kullanımıyla dikkat çekiyor. | Zip Perde Darıca

  25. ecommerce表示:

    Wow, amazing weblog structure! How lengthy have you been blogging for?
    you make running a blog look easy. The entire glance of your site is great, let alone the
    content! You can see similar here sklep internetowy

  26. Proje Planı Nasıl Oluşturulur? | Bir süre önce bu bloga rastladım ve çok memnun oldum. Özellikle bu yazı, beni gerçekten aydınlatıcı oldu.

  27. Hadımköy / Arnavutköy Karotçu | Rüzgar Karot’un profesyonel yaklaşımı ve hızlı geri dönüşleri işlerimi çok kolaylaştırdı, teşekkürler!

  28. Hasanpaşa, Sultanbeyli Köşe Takımı Yıkama | PENTA’nın sunduğu çözümler, işletmelerin temizlik ve hijyen konusundaki ihtiyaçlarını karşılamak için mükemmel bir seçenek gibi görünüyor. Harika bir hizmet sunuyorlar!

  29. Venster Systems’in sineklikleri, kaliteli malzemeleri ve sağlam yapısıyla gerçekten dikkat çekiyor. | Sineklik Modelleri

  30. Midden-Drenthe | Deze blog heeft me doen beseffen dat MAFA echt de toonaangevende autoriteit is op het gebied van webdesign en softwareontwikkeling. Hun werk is gewoonweg verbluffend.

發佈回覆給「Yomra / Trabzon Web Tasarım」的留言 取消回覆

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