Make jpeg canvas animation "responsive" -


improve html5 canvas frame frame jpg animation cache before animating

the above code snippet great. i'd able apply new widths css/media queries canvas holds jpgs. there way add above code?

when tried jpg's became wildly oversized.

it appears in above code height , width declared in js image , height , width on canvas tag need match or things wonky.

i want dynamically call image width css , media queries. thanks

<style type="text/css"> /*css full screen animation.you may want remove this*/ html,body {  height:100%;  width:100%;  padding:0;  margin:0;  } /*id canvas jpg animation - sets size, background image , loader*/ #anim {  background-image:url('images/icon_loading_75x75.gif'),url('images/t5.png'); /*center=loading gif, left top= placeholder image*/ background-position: center, left top; background-repeat: no-repeat; height:500px;  width:660px; } </style>   <script type="text/javascript"> function draw() { var ctx = document.getelementbyid('anim').getcontext("2d"); var start = 1, stop = 121,cur=start,imgarr=[];  //pre-loads images var loadloop = function() { var img = document.createelement("img"); img.onload = function() { imgarr.push(this); cur++;  if(cur > stop) { // images preloaded animate(); } else { loadloop(); } }  //img.src = "jpg_80/t5_"+(cur)+".jpg"; img.src = "http://html5canvas.syntheticmedia.net/jpg_80/t5_"+(cur)+".jpg"; //jpg_80/t5_88.jpg }  loadloop();  //canvas jpg animation function animate() { var timer = setinterval(function() { ctx.drawimage(imgarr.shift(), 0, 0 ); if(imgarr.length == 0) { // no more frames clearinterval(timer); } //framerate @ 24 frames per second },1000/24); } } </script> <script src="modernizr-2.6.2.min.js" type="text/javascript"> </script> <body>  <!-- html5 canvas animation--> <canvas id="anim" width="660" height="500"></canvas>  <script> //call after page loaded window.onload = draw;  </script> </body> 


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -