小编Ras*_*hid的帖子

如何不间断地连续播放声音?

我正在尝试在基于浏览器的游戏中播放车辆驱动的声音(连续不间断)。
我的 .wav 文件长度为 1 秒,并且从头到尾具有相同的频率。但是在下一次迭代之前,声音需要休息一下。
这是代码:

function playSound()
{
    //alert("");
    myAudio = new Audio('http://ithmbwp.com/feedback/SoundsTest/sounds/tank_driven.wav'); 
    if (typeof myAudio.loop == 'boolean')
    {
        myAudio.loop = true;
    }
    else
    {
        myAudio.addEventListener('ended', function() {
            this.currentTime = 0;
            this.play();
        }, false);
    }
    myAudio.volume = 0.3;
    myAudio.play();
}
Run Code Online (Sandbox Code Playgroud)

谁能帮我连续播放声音?

版

您可以在这里访问我的页面以观察问题。

function playSound()
{
    //alert("");
    myAudio = new Audio('http://ithmbwp.com/feedback/SoundsTest/sounds/tank_driven.wav'); 
    if (typeof myAudio.loop == 'boolean')
    {
        myAudio.loop = true;
    }
    else
    {
        myAudio.addEventListener('ended', function() {
            this.currentTime = 0;
            this.play();
        }, false);
    }
    myAudio.volume = 0.3; …
Run Code Online (Sandbox Code Playgroud)

html javascript audio audio-streaming html5-audio

5
推荐指数
1
解决办法
2001
查看次数

如何将容器div及其所有内容缩放到特定大小?

我创建了一个100%(浏览器)宽度的HTML页面,其中包含大量内容.内容在页面中固定,这些大小都以像素和百分比表示.
现在我需要添加20%浏览器宽度的广告面板.并且想要将页面容器及其所有内容(包括文本)缩放到80%(就像在所有Web浏览器中可用的缩放,但它应该是内部缩放).
不幸的是,我的页面没有响应,我不想重新开发它或从头开始调整其所有内容.
HTML中是否有可用的缩放功能?

html javascript css jquery html5

5
推荐指数
1
解决办法
1万
查看次数

如何控制(音频缓冲区)AudioContext()的音量?

我在JavaScript中有以下AudioContext()声音对象。
其体积为100%。我想以10%的音量播放(音量= 0.1)。
如何将其音量减小到10%?

const aCtx = new AudioContext();
let source = aCtx.createBufferSource();
let buf;
fetch('https://dl.dropboxusercontent.com/s/knpo4d2yooe2u4h/tank_driven.wav') // can be XHR as well
  .then(resp => resp.arrayBuffer())
  .then(buf => aCtx.decodeAudioData(buf)) // can be callback as well
  .then(decoded => {
    source.buffer = buf = decoded;
    source.loop = true;
    source.connect(aCtx.destination);
    check.disabled = false;
  });

check.onchange = e => {
  if (check.checked) {
    source.start(0); // start our bufferSource
  } else {
    source.stop(0); // this destroys the buffer source
    source = aCtx.createBufferSource(); // so we need …
Run Code Online (Sandbox Code Playgroud)

javascript audio audiobuffer

4
推荐指数
1
解决办法
5724
查看次数

如何将点以指定角度平移到指定距离?

我想沿着角度以度为单位的直线将点转换为特定距离。

var initialPoint = [0,0];   //Starting Point
var distance = 100;         //Distance in pixels to be translated
var degree = 45;            //Direction of move
var translatedPoint = moveByDegree(initialPoint, degree, distance);

function moveByDegree(initialPoint, degree, distance)
{
    //formula to generate translatedPoint by degree & distance
    // . . . 

    return translatedPoint;
}
Run Code Online (Sandbox Code Playgroud)
  • 0度应向上移动。
  • 180度应向下移动。
  • 90度应向右移动。
  • 270度应向左移动。
  • 其他角度将对应于对角线方向。

给我简单的算法或JavaScript代码。

javascript math geometry trigonometry

3
推荐指数
1
解决办法
1747
查看次数

内部div在梯形形状的div中是不可见的

我试图在梯形形状的div内设置一个div.
但无论如何,内在的div是无形的.
我也试过z-indexes.

.trapezoid
{
    border-color: transparent transparent rgba(255,0,0,0.2) transparent;
    border-width: 0px 10px 38px 10px;
    border-style: solid;
    height: 0;
    width: 40px;
    background-size: 430px;
    overflow: hidden;
    background-repeat: no-repeat;
    display: block;
    text-indent: -99999px;
    margin-top: 25px;
    margin-bottom: 25px;
    margin-left: 25px;
    margin-right: 25px;
    cursor: pointer;
}
.innerIcon
{
    width: 100%;
    height: 38px;
    border-radius: 16px;
    background-color: rgba(0,0,0,0.4);
}
Run Code Online (Sandbox Code Playgroud)
<div class="trapezoid" title="Fire Range Down">
    	<!-- This inner div is invisible -->
	<div class="innerIcon"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

请给我一些解决方案.

html css html5 css3

2
推荐指数
1
解决办法
110
查看次数