Javascript to display image center screen on event -


i'm writing script wait put in code (up down down left right left right b a) play sound , display gif centered on screen, removed when gif done playing.

my problem don't know how display gif without document.body.appendchild() places @ bottom left of site. also, don't know how make go away when done.

if (window.addeventlistener) {    var keys = [],      sequence = "38,38,40,40,37,39,37,39,66,65";    window.addeventlistener("keydown", function(e) {      keys.push(e.keycode);        if (keys.tostring().indexof(sequence) >= 0) {        // such as:                var iga = document.createelement("img");              iga.src = "http://s18603.storage.proboards.com/6408603/i/nhmcfco61njyc1vlzrdy.gif";              document.body.appendchild(iga);                        var audio = new audio('http://www.myinstants.com/media/sounds/igathrow.mp3');        audio.play();            keys = [];      };    }, true);  };

there multiple possible solutions, without seeing page code (and assuming you're trying in vanilla javascript) solution that's universal use javascript set image's position property absolute, , position image retrieving screen dimensions.

 var winw = 630, winh = 460; if (document.body && document.body.offsetwidth) {  winw = document.body.offsetwidth;  winh = document.body.offsetheight; } if (document.compatmode=='css1compat' &&     document.documentelement &&     document.documentelement.offsetwidth ) {  winw = document.documentelement.offsetwidth;  winh = document.documentelement.offsetheight; } if (window.innerwidth && window.innerheight) {  winw = window.innerwidth;  winh = window.innerheight; }  console.log('window center x = '+(winw/2)); console.log('window center y = '+(winh/2)); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -