Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript以编程方式生成波形_Javascript_Jquery_Html_Css - Fatal编程技术网

使用Javascript以编程方式生成波形

使用Javascript以编程方式生成波形,javascript,jquery,html,css,Javascript,Jquery,Html,Css,这是我目前拥有的 这是可行的,但我希望它像波浪一样。它应该看起来像一个真实的波浪,而不是一个“v”形。你是如何逐渐做到这一点的 var height = 0; setInterval(function () { $('#container').prepend('<div style="height:' + Math.abs(height++) + '%"></div>'); height = (height == 100) ? -100 : height

这是我目前拥有的

这是可行的,但我希望它像波浪一样。它应该看起来像一个真实的波浪,而不是一个“v”形。你是如何逐渐做到这一点的

var height = 0;

setInterval(function () {
    $('#container').prepend('<div style="height:' + Math.abs(height++) + '%"></div>');
    height = (height == 100) ? -100 : height;
}, 10);
只需使用来模拟波浪

var i=5,高度=0;
setInterval(函数(){
$(“#容器”)。前缀(“”);
i+=0.05;
高度=50*数学sin(i)+50;
}, 10);

如果要使波浪更平滑,请减小元素的增量值和宽度。这是一个例子

有许多不同种类的波。您创建的一个称为三角波。也许你想创建一个正弦波?
html, body, #outerContainer, #container {
    height:100%;
}
#outerContainer {
    display : table;
}
#container {
    display : table-cell;
    vertical-align:bottom;
    white-space:nowrap;
}
#container > div {
    width:5px;
    background:black;
    display:inline-block;
}
var i = 5, height = 0;
setInterval(function () {
    $('#container').prepend('<div style="height:' + height + '%"></div>');
    i += 0.05;
    height = 50 * Math.sin(i) + 50;
}, 10);