找到 598 篇文章,关于 前端脚本
856 次浏览
要随机播放,请按以下方式添加歌曲:init ([ 'http://demo.com/songs/song1.mp3, 'http://demo.com/songs/song2.mp3, 'http://demo.com/songs/song3.mp3 ]);使用以下方法使用 Math.random 随机播放:function displayRandom() { var audio = Math.floor(Math.random() * (collection.length)); audio = collection[audio]; audio.play(); setTimeout(loop,audio.duration*1000); }
170 次浏览
HTML5 canvas 提供了 compositing 属性 globalCompositeOperation,它会影响所有绘图操作。 var compositeTypes = [ 'source-over','source-in','source-out','source-atop', 'destination-over','destination-in','destination-out', 'destination-atop','lighter','darker','copy','xor' ]; function drawShape(){ for (i = 0; i < compositeTypes.length; i++){ var label = document.createTextNode(compositeTypes[i]); document.getElementById('lab'+i).appendChild(label); var ctx = document.getElementById('tut'+i).getContext('2d'); // 绘制矩形 ctx.fillStyle = "#FF3366"; ctx.fillRect(15,15,70,70); // 设置合成属性 ctx.globalCompositeOperation = compositeTypes[i]; // 绘制圆形 ctx.fillStyle = "#0066FF"; ctx.beginPath(); ctx.arc(75,75,35,0,Math.PI*2,true); ctx.fill(); } }
2K+ 次浏览
要混合,您需要按 50-50 的比例混合两张图像。让我们看看如何操作:混合图像 window.onload = function () { var myImg1 = document.getElementById('myImg1'); var myImg2 = document.getElementById('myImg2'); var myCanvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); // 宽度和高度 var w = img1.width; var h = img1.height; myCanvas.width = w; myCanvas.height = h; var pixels = 4 ... 阅读更多
115 次浏览
Web RTC 需要浏览器之间进行点对点通信。此机制需要信令、网络信息、会话控制和媒体信息。Web 开发人员可以选择不同的机制在浏览器之间进行通信,例如 SIP 或 XMPP 或任何双向通信。createSignalingChannel() 的示例:var signalingChannel = createSignalingChannel(); var pc; var configuration = ...; // 运行 start(true) 以发起呼叫 function start(isCaller) { pc = new RTCPeerConnection(configuration); // 将任何 ice 候选者发送到另一个对等方 pc.onicecandidate = function (evt) { signalingChannel.send(JSON.stringify({ "candidate": evt.candidate })); }; // 一旦远程流 ... 阅读更多
193 次浏览
以下函数是 IndexedDB 添加数据的示例:function add() { var request = db.transaction(["employee"], "readwrite") .objectStore("employee") .add({ id: "001", name: "Amit", age: 28, email: "demo1@example.com" }); request.onsuccess = function(event) { alert("Amit 已添加到您的数据库。"); }; request.onerror = function(event) { alert("无法添加数据\rAmit 已存在于您的数据库中!"); } }上面,我们在数据库中添加了以下详细信息:const employeeData = [ { id: "001", name: "Amit", age: 28, email: "demo1@example.com" }, ];
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP


