サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
レイングッズ
qiita.com/economist
要素をドラッグして移動することは、JavaScriptにおいて頻出パターンです。 しかし、それを簡単に実現するコードは意外と知られていません。 <img id="$img" src="https://js.cx/clipart/ball.svg" width="40" height="40"> <script> $img.onpointermove = function(event){ if(event.buttons){ this.style.left = this.offsetLeft + event.movementX + 'px' this.style.top = this.offsetTop + event.movementY + 'px' this.style.position = 'absolute' this.draggable = false this.setPointe
JavaScriptで文字列をハッシュ化する方法を探していた。 ライブラリを使わず、ブラウザだけでできないかなーと。 ようやく見つけたので記録に。 async function sha256(text){ const uint8 = new TextEncoder().encode(text) const digest = await crypto.subtle.digest('SHA-256', uint8) return Array.from(new Uint8Array(digest)).map(v => v.toString(16).padStart(2,'0')).join('') }
JavaScriptで複数の画像を読み込みたい。しかも高速に。 初心者にとっては鬼門の処理ですが、2021年現在だとこのように書きます。 function loadImages(list){ async function load(src){ const img = new Image() img.src = src await img.decode() return img } return Promise.all(list.map(src => load(src))) }
<form id="form"> 音声<input id="audio" type="file" required><br> 画像<input id="image" type="file" required><br> <button id="button">音声と画像から動画を作成する</button> </form> <video id="video" controls></video> <script> form.onsubmit = function(event){ event.preventDefault() button.disabled = true ffmpeg('-y', '-loop', 1, '-i', image.files[0], '-i', audio.files[0], '-pix_fmt', 'yuv420p', '-shortest', 'out.mp4')
async function autosave_state(url, id, password){ const r = new FormData() r.append('r', JSON.stringify({id, password})) const http = await fetch(url, {method:'POST', mode:'cors', credentials:'include', body:r}) const state = await http.json() window.addEventListener('beforeunload', function(){ const w = new FormData() w.append('w', JSON.stringify({id, password, state})) navigator.sendBeacon(url,
このページを最初にブックマークしてみませんか?
『@economistのマイページ - Qiita』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く