Tải lại javascript SVG

The restart attribute is used to decide whether an animation will restart or not. The attribute is used by the , , , and elements.

cú pháp

restart="always | whenNotActive | never"

Giá trị thuộc tính. Thuộc tính này chấp nhận ba giá trị như đã đề cập ở trên và được mô tả bên dưới

  • luôn. Nó chỉ định rằng hoạt ảnh luôn có thể được khởi động lại
  • khiNotActive. Nó chỉ định rằng hoạt ảnh chỉ có thể được khởi động lại khi nó không hoạt động. Nếu một người cố gắng khởi động lại hoạt ảnh trong thời gian hoạt động thì những nỗ lực đó sẽ bị bỏ qua
  • chẳng bao giờ. Nó chỉ định rằng không thể khởi động lại hoạt ảnh trong thời gian tài liệu được tải

Các ví dụ dưới đây minh họa việc sử dụng thuộc tính này

ví dụ 1

HTML




_______3____4____5

 

<body>

const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
0______31 234>

6<____2898>

 

6<<5 <63<8

_______39____40____23____42>

 

<9<html7 html83>0 >13>3 >43>6

>7_______58____23>6  13 3>

 

>7______3 8  93<1

<2______333>3 <63<8 <93body1

<2body3____23body5

<2______87____23body9 >0

<9>2____47>

 

<9<>8 >93

const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
01 23
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
04>

>7______3

const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
08 2301 html8322>


Định nghĩa và cách sử dụng

Phương thức

const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
07 tải lại tài liệu hiện tại

Phương pháp

const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
07 thực hiện tương tự như nút tải lại trong trình duyệt của bạn


cú pháp

Thông số

Giá trị trả về


Hỗ trợ trình duyệt

const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
09 được hỗ trợ trong tất cả các trình duyệt

ChromeEdgeFirefoxSafariOperaIECóCóCóCóCóCó

Như @rzelek đã đề cập, hình ảnh SVG sẽ tự cập nhật nếu bạn thêm các phần tử bằng

const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
10 thay vì gán cho
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
11

Một lưu ý, mặc dù. bạn phải chỉ định không gian tên

const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
12 trên thành phần bạn tạo bằng cách sử dụng
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
13, thay vì
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);
14 bình thường

Ví dụ

const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
circle.setAttribute('r', '50');
circle.setAttribute('cx', '50');
circle.setAttribute('cy', '50');
circle.setAttribute('fill', 'red');
document.getElementById('svg').appendChild(circle);

JSFiddle