jquery - Evaluate orientationEvent and setting a value? -


if have onchange function firing when orientation change has happened, how set value within onchange update jquery selector. instance:

  $(document).ready(function(){         var onchanged = function() {             if(window.orientation == 90 || window.orientation == -90){                 image = '<img src="images/land_100.png">';             }else{                 image = '<img src="images/port_100.png">';             }      }         $(window).bind(orientationevent, onchanged).bind('load', onchanged);         $('#bgimage').html(image); //won't update image    }); 

you need put update image inside onchanged function every time orientation changes, image html changed.

$(document).ready(function(){        // event orientation change    var onchanged = function() {        // orientation       var orientation = window.orientation,        // if landscape, use "land" otherwise use "port"       image = orientation == 90 || orientation == -90 ? "land" : "port";        // insert image       $('#bgimage').html('<img src="images/'+image+'_100.png">');     };     // bind orientation change event , bind onload    $(window).bind(orientationevent, onchanged).bind('load', onchanged);  }); 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -