LANG SELRCT

Google Apps Scriptのコードを書く場所  (新規作成: スプレッドシート | スクリプトエディタ

2021年5月5日水曜日

JavaScriptのanimate()でアニメーションを試してみたい


Elementの透明度と位置をアニメーションさせたい。

Element.animate() で実装できました。


デモ




コード.gs
function doGet() {
  return HtmlService.createHtmlOutputFromFile("index");
}
意訳
この機能がやること
指定したHTMLファイルを表示する




index.html
<!DOCTYPE html>
<html>

<body>
<textarea id="ta">hello</textarea>
<script>

animation();
function animation() {
  elem("ta").animate({
    "opacity": [ 0, 1 ], // [ フレーム 1, フレーム 2 ]
    "color": [ "#fff", "#000" ] // [ フレーム 1, フレーム 2 ]
    },
    {
      "duration": 2000,
      "iterations": Infinity
    })

  elem("ta").animate({
    "marginLeft": ["0px", "100px"]
    },
    {
      "duration": 1000,
      "easing": "ease",
      "iterations": Infinity
    })
  
  // 移動後の位置を設定しないと元に戻る
  elem("ta").style.marginLeft = "100px";
}

function elem(id) {
  return document.getElementById(id);
}

</script>
</body>
</html>



参考

Element.animate()

Animation

Keyframe Formats

EffectTiming

最新の投稿

JIRA APIで選択リスト(複数選択)を課題作成時に選択してPOSTしたい

JIRA APIを利用して選択リスト(複数選択)フィールドに値を入れたくて書いたコードです。 コード.gsのこの部分で複数選択の値を選択できました。 customfield_10043 は手元のJIRAでの選択リスト(複数選択)のフィールドIDなので、各自の環境によって異なります...