第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將隨機數(shù)值放入 svg“fill”屬性的“rgb()”中?

如何將隨機數(shù)值放入 svg“fill”屬性的“rgb()”中?

慕標5832272 2023-10-10 10:30:25
我的網(wǎng)站上有一個svg元素,我想對其進行動畫處理,以便它從隨機顏色值更改為另一個隨機顏色值。我現(xiàn)在擁有的看起來像這樣:<?xml version="1.0" standalone="no"?><svg width="8cm" height="3cm" viewBox="0 0 800 300" xmlns="http://www.w3.org/2000/svg">  <desc>Example anim01 - demonstrate animation elements</desc>  <rect x="1" y="1" width="900" height="400"        fill="none" stroke="none" stroke-width="2" />  <!-- The following illustrates the use of the 'animate' element        to animate a rectangles x, y, and width attributes so that        the rectangle grows to ultimately fill the viewport. -->  <rect id="RectElement" x="300" y="100" width="300" height="100"        fill="rgb(0,255,0)"  >    <animate attributeName="fill" begin="0" dur="1.3"    fill="remove" from="rgb(0,255,0)" to="rgb(255,0,0)" repeatCount="indefinite"/>    <animate attributeName="x" begin="0s" dur="1.3s"             fill="freeze" from="300" to="0" repeatCount="indefinite"/>    <animate attributeName="y" begin="0s" dur="1.3s"             fill="freeze" from="100" to="0" repeatCount="indefinite"/>    <animate attributeName="width" begin="0s" dur="1.3s"             fill="freeze" from="300" to="800" repeatCount="indefinite"/>    <animate attributeName="height" begin="0s" dur="1.3s"             fill="freeze" from="100" to="300" repeatCount="indefinite"/>          </rect>  <!-- Set up a new user coordinate system so that        the text string's origin is at (0,0), allowing        rotation and scale relative to the new origin -->  <g transform="translate(100,100)" >    <!-- The following illustrates the use of the 'set', 'animateMotion',         'animate' and 'animateTransform' elements. The 'text' element         below starts off hidden (i.e., invisible). At 3 seconds, it:           * becomes visible           * continuously moves diagonally across the viewport           * changes color from blue to dark red           * rotates from -30 to zero degrees           * scales by a factor of three. -->但我想要的是為矩形分配一個隨機顏色值(類似于“rgb(隨機#,隨機#,隨機#)”)。我該如何做才能確保每種顏色都是可能的結(jié)果?
查看完整描述

1 回答

?
猛跑小豬

TA貢獻1858條經(jīng)驗 獲得超8個贊

let refreshRate = 1300;


function rand(max){

  return Math.floor(Math.random() * (max+1));

};


setInterval(function(){


document.getElementById("RectElement").setAttribute("fill","rgb("+rand(255)+", "+rand(255)+", "+rand(255)+")");


},refreshRate);


查看完整回答
反對 回復 2023-10-10
  • 1 回答
  • 0 關(guān)注
  • 132 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號