2010-09-02 35 views
26

Tôi có chuỗi các animationTransform:Làm thế nào để lặp lại chuỗi hoạt ảnh SVG?

<animateTransform attributeName="transform" attributeType="XML" type="rotate" from="0" to="30" begin="0s" dur="0.4s" fill="freeze"/> 
<animateTransform attributeName="transform" attributeType="XML" type="rotate" from="30" to="0" begin="0.4s" dur="0.4s" fill="freeze"/> 

Nếu nó có thể để lặp chuỗi này mà không cần sử dụng kịch bản?

Tôi có thể đặt hoạt ảnh riêng lẻ thành vòng lặp bằng cách sử dụng repeatCount="indefinite" bởi tôi muốn lặp lại toàn bộ chuỗi theo thứ tự.

Trả lời

34

Đã tìm ra. Giải pháp cho những ai quan tâm:

<animateTransform id="anim1" attributeName="transform" attributeType="XML" type="rotate" from="0" to="30" begin="0s; anim2.end" dur="0.4s" fill="freeze"/> 
<animateTransform id="anim2" attributeName="transform" attributeType="XML" type="rotate" from="30" to="0" begin="anim1.end" dur="0.4s" fill="freeze"/> 
+1

trình trong (oold) Firefox 10, không hoạt động trong (up-to-date) Chrome 32, chỉ nếu có ai gặp các cùng một vấn đề. Và một số liên kết hữu ích mô tả tất cả các khả năng của thời gian hoạt ảnh: [W3C SVG 1.1 Spec.] (Http://www.w3.org/TR/SVG/animate.html#TimingAttributes), [Developer.Mozilla.org] (https : //developer.mozilla.org/en-US/docs/Web/SVG/Attribute/begin). – Jeyekomon

+0

Có thể xác nhận điều này không hoạt động trong Chrome 34. – hamishtaplin

27

Bạn cũng có thể chỉ là vòng lặp trong một đơn animateTransform bằng cách cung cấp một thuộc tính values với một dấu chấm phẩy tách ra danh sách:

<animateTransform attributeName="transform" type="rotate" 
    values="0;30;0" begin="0s" dur="0.8s" fill="freeze" 
    repeatCount="indefinite" /> 

Here's an example (kiểm tra trong Firefox 4.0 và Chrome).

+0

Tôi thích giải pháp này. Bạn có thể cho biết nơi tìm tài liệu thuộc tính animateTransform 'values' SVG không? Thật không may là một từ khá phổ biến cho một tìm kiếm web thông thường. Cảm ơn! – jtheletter

+2

@janaspage Tôi chỉ tình cờ gặp tài liệu về thuộc tính giá trị tại đây: http://www.w3.org/TR/smil-animation/#ValuesAttribute – chrisM

6

nó cũng có thể thêm/trừ (milli) giây:

begin="anim2.end-500ms" 
Các vấn đề liên quan