jquery - Add to CSS integer every x seconds using JavaScript -


i'm making "fake" loading icon. want give impression of loading calculations in reality quick enough doesn't take long load...

instead want set increment animation along every second until "complete". using css3 animations animation , using css hover action. can see here if hover on icon: http://jsfiddle.net/77gkzqo2/

what able increment relevant css every second.

currently "beer" has starting css (the glass unfilled):

border-top:2px solid #f9f1dc;  height:20%; 

by end of animation has reached:

border-top:14px solid #f9f1dc; height:68%; 

how can use jquery or javascript increment this?

the difference border 12. difference height percentage 48.

perhaps every 1 second, border size increases 4px , height percentage increases 16%. means take 3 seconds reach ending size.

i struggling javascript have no idea whats best use. i've written pseudo code guess no idea if i'm on right track or how flesh out.

function addcss(){    // somehow increment each value    var height = [the css height]    var border = [the css border]    var newheight = height + 16;    var newborder = border + 4;     [set var newheight .filler's height]    [set var newborder .fillers border size] }  setinterval('addcss();', 1000);  

you don't need jquery that. plus, i'm not sure wan't on :hover, think want once when page loaded right? if want animate js every second, don't think having css in it's final states option.

a simple way that in native js:

var filler = document.getelementbyid('filler'); var border = 2, height = 20;  var animate = setinterval(function() {     if (border < 15) {         border += 0.10;         filler.style.bordertopwidth = border + 'px';     }     if (height < 68) {         height += 0.40;         filler.style.height = height + '%';     }      if (border>=15 && height>=68)         clearinterval(animate); }, 50); 

you have better perf' using jquery , wouldn't recommend using jquery if not comfortable js.

of course lot improved if want simple fake loader work.

just question: why want make website slow if isn't?


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -