html - Multiple Backgrounds updated with jquery -


i have experience css , various javascript libraries have been struggling on incorporating multiple backgrounds code got off http://codepen.io/quasimondo/pen/lddrf. wanted throw transparent .png on top of animated gradient.

i tried attaching png different section of website (body, div) doesn't seem work correctly lose finer control of it. whenever try add $('#gradient').css function, errors out. assuming simple syntax issue don't know.

thanks looking. first post, searched through previous posts. if i've missed something, sorry.

jason

html

<!doctype html> <title>animated background gradient</title> <body> <div id="gradient" /> </body>    <script src="js/index.js"></script> 

css

body{ background-color: #000000; padding: 0px; margin: 0px; }  #gradient { width: 100%; height: 800px; padding: 0px; margin: 0px;} 

js

var colors = new array( [62,35,255],[60,255,60],[255,35,98],[45,175,230],[255,0,255],[255,128,0]);  var step = 0; var colorindices = [0,1,2,3];  var gradientspeed = 0.0006;  function updategradient() {  if ( $===undefined ) return;  var c0_0 = colors[colorindices[0]]; var c0_1 = colors[colorindices[1]]; var c1_0 = colors[colorindices[2]]; var c1_1 = colors[colorindices[3]];  var istep = 1 - step; var r1 = math.round(istep * c0_0[0] + step * c0_1[0]); var g1 = math.round(istep * c0_0[1] + step * c0_1[1]); var b1 = math.round(istep * c0_0[2] + step * c0_1[2]); var color1 = "rgb("+r1+","+g1+","+b1+")";  var r2 = math.round(istep * c1_0[0] + step * c1_1[0]); var g2 = math.round(istep * c1_0[1] + step * c1_1[1]); var b2 = math.round(istep * c1_0[2] + step * c1_1[2]); var color2 = "rgb("+r2+","+g2+","+b2+")";  $('#gradient').css({ background: "-webkit-gradient(linear, left top, right top, from("+color1+"), to("+color2+"))"}).css({ background: "-moz-linear-gradient(left, "+color1+" 0%, "+color2+" 100%)"});  step += gradientspeed; if ( step >= 1 ) { step %= 1; colorindices[0] = colorindices[1]; colorindices[2] = colorindices[3];  colorindices[1] = ( colorindices[1] + math.floor( 1 + math.random() * (colors.length - 1))) % colors.length; colorindices[3] = ( colorindices[3] + math.floor( 1 + math.random() * (colors.length - 1))) % colors.length;  } }   setinterval(updategradient,10); 

https://jsfiddle.net/byjrglass/f7vslss1/7/

you have take account css gradients behave images. example, this:

background: linear-gradient(to bottom, blue, white); 

produces same thing this:

background-image: linear-gradient(to bottom, blue, white); 

so use png image on top of that, need this:

background-image: url(image.png), linear-gradient(to bottom, blue, white) 

using code, here's example: http://codepen.io/anon/pen/wrjoql

or put gradient in body, instead of in div, , include image in div. here's example using code: http://codepen.io/anon/pen/gpzwvo


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -