javascript - Gradient only on one section -
on previous post asked how i'd gradient set up. problem gradient "spreads" out. here's i'm using
function generatecssgradient(colours) { var l = colours.length, i; for( i=0; i<l; i++) colours[i] = colours[i].join(" "); return "linear-gradient( right, "+colours.join(", ")+")"; } var cols = [ ["red","0%"], ["red","40%"], ["yellow","40%"], ["yellow","60%"], ["green","60%"], ["green","80%"] ]; yourelement.style.background = generatecssgradient(cols);
with this. want fill in 1 input. , bar goes 33%, red color. next blue , fourth. not this. ideas? i'd avoid using div
i think want this ... see source code
html
i'v edited html code , added div called colors
inside div top
...
<div class="top"> <div class="colors"></div> </div>
css
also edited css of .top
, added overflow:hidden;
, create .colors
style
.top{ /*background: #009dff;*/ background:linear-gradient(to right,#009dff 0,#00c8ff 100%); position:fixed; z-index:1031; top:0; left:0; height:4px; transition:all 1s; width:0; overflow: hidden; } .colors{ width: 100%; height: 4px; }
javsscript
then edited javascript , made cssgradient colors
not top
, , let javascript set width of colors
fit window width , , changed colors percentage..
document.queryselector(".colors").style.background = generatecssgradient(cols); var window_width = window.innerwidth + "px"; document.queryselector(".colors").style.width = window_width; var cols = [ ["red","0%"], ["red","33.3%"], ["yellow","33.3%"], ["yellow","66.6%"], ["green","66.6%"], ["green","100%"] ];
hope ...
update
if want change color of bar this , see source code ...
just edit javascript this
function cback(e) { var t = []; (var n = inputs.length; n--;) { if (!inputs[n].value.length) t.push(inputs[n]); } var r = t.length; var = inputs.length; var s = document.queryselectorall(".top"); (var o = s.length; o--;) { s[o].style.width = 100 - r / * 100 + "%"; s[o].style.background = cols[i-r-1]; } } var forms = document.queryselectorall(".form"), inputs = []; (var = forms.length; i--;) { var els = forms[i].queryselectorall("input, textarea, select"); (var j = els.length; j--;) { if (els[j].type != "button" && els[j].type != "submit") { inputs.push(els[j]); els[j].addeventlistener("input", cback, false); } } } var cols = ["red","yellow","green"];
Comments
Post a Comment