5

Web サイトで使用する必要がある、すべて個々の形状の Illustrator グラフィック (低解像度のスクリーンショットの下) が提供されています。

飛んでいる鳥、人や車の動き、ライトのオン/オフなど、グラフィックのセクションをアニメーション化する必要があります。

イラストレーター グラフィック

問題は、これをどのように行うべきかということです。私は、SVG、CSS、および JQuery アニメーションを調べてきました。これまでのところ、CSS と JQuery を非常に効果的に使用できます。

誰かがブラウザー ウィンドウのサイズを変更したときに (レスポンシブ レイアウト) アニメーションを機能させることができれば素晴らしいと思います。それが SVG を調べ始めた理由です。また、アニメーションがさまざまなブラウザー間で広く互換性を持つ必要があります。

例はありますか?あなたは何をお勧めします?

ありがとう。

編集:

JQuery とキーフレーム アニメーションを使用します。私が使用しているJqueryアニメーション関数は次のとおりです。


    function animatethis(targetElement, speed, options, options2) {
        $(targetElement).animate(options,
        {
            duration: speed,
            complete: function ()
            {
                targetElement.animate(options2,
                {
                    duration: speed,
                    complete: function ()
                    {
                        animatethis(targetElement, speed, options, options2);
                    }
                });
            }
        });
    };

使用例:

animatethis($('.big-cloud1'), 40000, {'left': '+=120%'}, {'left': '-=120%'})

また、ブラウザのサイズを変更するときに、個々の画像のサイズを計算しています。これは、全幅でのアニメーションの最大比率に基づいています。

このコードは次のとおりです。


// get main image
var mainImage = $('.main-bg');

// Create new offscreen image to test
var theImage = new Image();
theImage.src = mainImage.attr("src");

// Get accurate measurements from that.
var maxWidth = theImage.width;

jQuery.fn.resizeRatio = function(newHeight){
    // work out new ratio
    var currentWidth = $('.main-bg').width();
    var diff = maxWidth - currentWidth;
    var precent = diff / maxWidth;

    // get current image width
    var currentImage = new Image();
    currentImage.src = $(this).attr("src");
    var currentWidth = currentImage.width;

    // apply new width
    $(this).width(currentWidth - (currentWidth*precent))

}

var initAnimation = function(){
    $('#animation').imagesLoaded(function(){
        $('#animation img').not('.sun, .main-bg').each(function( index ) {
            $(this).resizeRatio()
        });     
    });
}
initAnimation()

$(window).resize(function(){
    initAnimation()
});
4

2 に答える 2

1

私は SVG の経験がありません。

ただし、CSS と jQuery を使用して、おそらくこのようなものを作成します。パーセンテージを使用して CSS で画像のサイズを変更すると、さまざまな種類の画面でこれを機能させることができるでしょう。ただし、すべてがうまく機能するようにするには、多くの作業が必要です。

すべてのjQueryもパーセンテージで実行する必要があるか、サイズ変更時に物事を行う必要があります。

jQuery(window).resize(function(){
    // Do your magic
});

ほとんどの場合、画像の高さではなく幅を操作する必要があるため、おそらく次の CSS を使用します。

img {
    width: (certain amount in percentages)
    height: auto;
}

これにより、画像が適切な比率に保たれます。(しかし、そのようなプロジェクトを開発することを計画していることを考えると、あなたはすでにそれを知っていたと思います).

私の考えをもう少し詳しく説明する必要がある場合は、喜んでそうします。ただし、これとは別に、これを行うためのより良い/高速な方法はありません (Flash が良い方法だと思わない限り)。

于 2013-10-30T15:35:17.337 に答える
1


このHTML のようなサイズ変更とアニメーションでsvgを使用できます

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 600 600" preserveAspectRatio="xMidYMid"  style="width:100%; height:100%; position:absolute; top:0; left:0; z-index:-1;">
<g id="targets">
    <g id="red">
        <rect id="rect_red" x="110" y="115" width="64" height="64" rx="8" ry="8" fill="#FF173D" stroke="#000000" transform="translate(-108, -114)" />
        <animateMotion id="animation_red" begin="0" end="indefinite" dur="10s" repeatCount="indefinite" path="M 0 0 H 500 Z"></animateMotion>
    </g>
    <g id="blue">
        <rect id="rect_blue" x="110" y="115" width="64" height="64" rx="8" ry="8" fill="#0000aa" stroke="#000000" />
        <animateMotion id="animation_blue" begin="indefinite" end="indefinite" dur="10s" repeatCount="indefinite" path="M 0 0 H 500 Z"></animateMotion>
    </g>
    <g id="gree">
        <rect id="rect_green" x="10" y="300" width="64" height="64" rx="8" ry="8" fill="#00aa00" stroke="#000000" />
        <animateMotion id="animation_green" begin="indefinite" end="indefinite" dur="5s" repeatCount="indefinite" path="M 0 0 H 300 Z"></animateMotion>
    </g>
</g>
</svg>    

「rect_red」のようにbegin属性でアニメーションを開始する
か、javascriptを使用してこのようにアニメーションを開始できます

//jQuery    
$(document).ready(function () {
$("#rect_blue").click(function(){
     $("#animation_blue").get(0).beginElement();
});
$(window).resize(function(){
     $("#animation_green").get(0).beginElement();
});
});    
//or javascript    
document.getElementById('rect_blue').addEventListener("click", function(){
    document.getElementById('animation_blue').beginElement();
}, false);
window.addEventListener("resize", function(){
    document.getElementById('animation_green').beginElement();
}, false);    

css を使用して、このような svg 要素のスタイルを設定できます

#rect_blue:hover{
    fill:#0000ff;
    cursor:pointer;
}
#rect_red:hover{
    fill:#aa0000;
    cursor:pointer;
}    

http://jsfiddle.net/Kv8Ju/1/

于 2013-10-30T16:20:42.150 に答える