Javascript 在chrome android/iOs上播放反应式css动画
我正在为我的声音设计学位做一个网站,我需要将音乐形象化。 我设法根据声音播放的“音量”(不透明度的变化)设置网站背景的动画。它在Chrome osx上很有魅力,但我不知道如何让它在android/iOS上工作。我应该为移动css动画使用特定的库吗 非常感谢 以下是他完整的我的代码:Javascript 在chrome android/iOs上播放反应式css动画,javascript,html,css,animation,mobile,Javascript,Html,Css,Animation,Mobile,我正在为我的声音设计学位做一个网站,我需要将音乐形象化。 我设法根据声音播放的“音量”(不透明度的变化)设置网站背景的动画。它在Chrome osx上很有魅力,但我不知道如何让它在android/iOS上工作。我应该为移动css动画使用特定的库吗 非常感谢 以下是他完整的我的代码: <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title&g
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Choir_Test</title>
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" rel="stylesheet" type="text/css">
<style>
body {
font-family:'Open Sans', serif; font-size:40px;
background-color:#000000;
padding : 0;
margin: 0;
width: 100%;
height: 100%;
}
Header {
position: center 40px;
height: 100px;
width: 100%;
color: white;
}
.contentWrapper {
width:1000px; margin-left: 40px; font-size:22px; font-weight:200;
}
h1 {
font-size:60px; font-weight:300;
}
.area {
height: 150px;
width: 100%;
color: white;
z-index:10;
padding : 0;
margin: 0;
}
#circularCenter {
margin: auto;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width:74px;
height:74px;
border-radius:100%;
background:rgb(255,0,0);
}
.circle {
background:rgba(255,0,0, 1);
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
-webkit-transition:0.1s ease all;
z-index:-1;
}
.initiator {
position:absolute;
width:100%; height:100%;
background:rgba(255,255,255, 0);
-webkit-transition:0.3s ease all;
z-index:1;
cursor:pointer;
}
.experiment {
background:rgba(0,0,0, 1);
background:-webkit-linear-gradient(#000,#000);
background:-moz-linear-gradient(#000,#000);
background:-ms-linear-gradient(#000,#000);
width:100%;
height:100%;
position: center 40px;
background-image:url(Images/Choirs.png);
background-size:150px 75px;
background-attachment:fixed;
background-repeat:no-repeat;
background-position:center 40px;
z-index: 100;
height: 100%;
Width: 100%;
padding : 0;
margin: 0;
}
.header
{
height: 100px;
padding-right: auto;
padding-left:auto;
z-index: 1000;
}
.footer
{
position: absolute;
bottom: 0px;
height: 30px;
padding-left:40px;
margin-bottom: 40px;
z-index: 750;
-webkit-filter: invert(100%);
}
</style>
</head>
<body>
<div class="experiment" id="r3">
<div class="initiator"></div>
<div id="circles" class="area"></div>
<div id="circles" class="footer">
<a href="http://twitter.com"><img src="Images/Twitter.png" width="40px"></img></a>
<a href="http://facebook.com"><img src="Images/Facebook.png" width="40px"></img></a>
</div>
</div>
</div>
<audio id="r0audio" loop>
<source src="Musics/China1.mp3"></audio>
<script>
window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext;
var renderers = {
'r0': (function() {
var barsArr = [],
initialized = false,
barsEl;
var height = 0;
var init = function(config) {
var count = config.count;
var width = config.width;
var barWidth = (width/count) >> 0;
height = config.height;
barsEl = document.getElementById('bars');
for(var i = 0; i < count; i++ ){
var nunode = document.createElement('div');
nunode.classList.add('bar');
nunode.style.width = barWidth + 'px';
nunode.style.left = (barWidth * i) + 'px';
barsArr.push(nunode);
barsEl.appendChild(nunode);
}
initialized = true;
};
var max = 256;
var renderFrame = function(frequencyData) {
for(var i = 0; i < barsArr.length; i++) {
var bar = barsArr[i];
bar.style.height = ((frequencyData[i]/max)*height + 'px');
}
};
return {
init: init,
isInitialized: function() {
return initialized;
},
renderFrame: renderFrame
}
})(),
'r3': (function() {
var circles = [];
var initialized = false;
var height = 0;
var width = 0;
var init = function(config) {
var count = config.count;
width = config.width;
height = config.height;
var circleMaxWidth = (width*0.99) >> 0;
circlesEl = document.getElementById('circles');
for(var i = 0; i < count; i++ ){
var node = document.createElement('div');
node.style.width = node.style.color = (i/count*circleMaxWidth) + 'px';
node.classList.add('circle');
circles.push(node);
circlesEl.appendChild(node);
}
initialized = true;
};
var max = 256;
var renderFrame = function(frequencyData) {
for(var i = 0; i < circles.length; i++) {
var circle = circles[i];
circle.style.cssText = '-webkit-transform:scale('+1+');';
circle.style.cssText += 'opacity:'+((frequencyData[i]/max))+';';
}
};
return {
init: init,
isInitialized: function() {
return initialized;
},
renderFrame: renderFrame
}
})(),
};
window.onload = function() {
function Visualization(config) {
var audio,
audioStream,
analyser,
source,
audioCtx,
canvasCtx,
frequencyData,
running = false,
renderer = config.renderer,
width = config.width || 360,
height = config.height || 360;
var init = function() {
audio = document.getElementById('r0audio');
audioCtx = new AudioContext();
analyser = audioCtx.createAnalyser();
source = audioCtx.createMediaElementSource(audio);
source.connect(analyser);
analyser.connect(audioCtx.destination);
analyser.fftSize = 64;
frequencyData = new Uint8Array(analyser.frequencyBinCount);
renderer.init({
count: analyser.frequencyBinCount,
width: width,
height: height
});
};
this.start = function() {
audio.play();
running = true;
renderFrame();
};
this.stop = function() {
running = false;
audio.pause();
};
this.setRenderer = function(r) {
if (!r.isInitialized()) {
r.init({
count: analyser.frequencyBinCount,
width: width,
height: height
});
}
renderer = r;
};
this.isPlaying = function() {
return running;
}
var renderFrame = function() {
analyser.getByteFrequencyData(frequencyData);
renderer.renderFrame(frequencyData);
if (running) {
requestAnimationFrame(renderFrame);
}
};
init();
};
var vis = document.querySelectorAll('.initiator');
var v = null;
var lastEl;
var lastElparentId;
for(var i=0; i<vis.length; i++) {
vis[i].onclick = (function() {
return function() {
var el = this;
var id = el.parentNode.id;
if (!v) {
v = new Visualization({renderer: renderers[id] });
}
v.setRenderer(renderers[id]);
if (v.isPlaying()) {
if (lastElparentId === id) {
v.stop();
el.style.backgroundColor = 'rgba(0,0,0,0.5)';
} else {
lastEl.style.backgroundColor = 'rgba(0,0,0,0.5)';
el.style.backgroundColor = 'rgba(0,0,0,0)';
}
}else {
v.start();
el.style.backgroundColor = 'rgba(0,0,0,0)';
}
lastElparentId = id;
lastEl = el;
};
})();
}
};
</script>
</body>
</html>
唱诗班测验
身体{
字体系列:“开放式Sans”,衬线;字体大小:40px;
背景色:#000000;
填充:0;
保证金:0;
宽度:100%;
身高:100%;
}
标题{
位置:中心40px;
高度:100px;
宽度:100%;
颜色:白色;
}
.contentWrapper{
宽度:1000px;左边距:40px;字体大小:22px;字体重量:200;
}
h1{
字体大小:60px;字体重量:300;
}
.区域{
高度:150像素;
宽度:100%;
颜色:白色;
z指数:10;
填充:0;
保证金:0;
}
#循环中心{
保证金:自动;
位置:绝对位置;
排名:0;
左:0;
底部:0;
右:0;
宽度:74px;
高度:74px;
边界半径:100%;
背景:rgb(255,0,0);
}
.circle{
背景:rgba(255,0,0,1);
位置:绝对位置;
排名:0;
左:0;
底部:0;
右:0;
-webkit过渡:0.1s轻松所有;
z指数:-1;
}
.发起人{
位置:绝对位置;
宽度:100%;高度:100%;
背景:rgba(255255,0);
-webkit过渡:0.3s轻松全部;
z指数:1;
光标:指针;
}
.实验{
背景:rgba(0,0,0,1);
背景:-webkit线性梯度(#000,#000);
背景:-moz线性梯度(#000,#000);
背景:-ms线性梯度(#000,#000);
宽度:100%;
身高:100%;
位置:中心40px;
背景图片:url(Images/Choirs.png);
背景尺寸:150px 75px;
背景附件:固定;
背景重复:无重复;
背景位置:中心40px;
z指数:100;
身高:100%;
宽度:100%;
填充:0;
保证金:0;
}
.标题
{
高度:100px;
右侧填充:自动;
左填充:自动;
z指数:1000;
}
.页脚
{
位置:绝对位置;
底部:0px;
高度:30px;
左侧填充:40px;
边缘底部:40px;
z指数:750;
-webkit过滤器:倒置(100%);
}
window.AudioContext=window.AudioContext | | window.webkitadiocontext | | window.mozadiocontext;
变量渲染器={
“r0”:(函数(){
var barsArr=[],
初始化=假,
巴塞尔;
var高度=0;
var init=函数(配置){
var count=config.count;
var width=config.width;
var barWidth=(宽度/计数)>>0;
高度=配置高度;
barsEl=document.getElementById('bar');
对于(变量i=0;i>0;
circlesEl=document.getElementById('circles');
对于(变量i=0;i