2

I have one problem when i use window orientation change event its not firing on devices. Here, i have added my code. Please help me out from this issue.

Example code,

define(["jquery"], function($) {
    $(function() {
        set_screen();
    });

    function set_screen(){
        var winH = $(window).height(),
            winW = $(window).width();
        $('.fullscreen-slider ul.slide li').css({'height':winH});
    }

    $(window).on("orientationchange", function(event) {
        set_screen();
    });
});
lshettyl
  • 7,854
  • 4
  • 21
  • 28
Sathya
  • 1,466
  • 1
  • 25
  • 51

1 Answers1

0

This may explain why you are not getting the window height you expect, though we would need to see your HTML and CSS to be sure:

jquery $(window).height() is returning the document height

That said, as @LShetty pointed out in comments above, you can achieve the same result much more easily by simply giving the element a height of 100%. Best to do this in a stylesheet file, but if you have to do it in Javascript:

define(["jquery"], function($) {
    $(function() {
        $('.fullscreen-slider ul.slide li').css({'height':'100%'});
    });
});

No orientationchange handler needed.

Community
  • 1
  • 1
radiaph
  • 3,711
  • 1
  • 14
  • 19
  • "When a number is passed as the value, **jQuery will convert it to a string and add px to the end of that string.** If the property requires units other than px, convert the value to a string and add the appropriate units before calling the method." (Documentation of [`.css()`](https://api.jquery.com/css/). Emphasis added.) – Louis May 14 '15 at 17:53
  • @Louis, thanks, didn't know that. Will edit answer to reflect. – radiaph May 14 '15 at 18:15
  • If i write like this, $(window).on("orientationchange", function(event) {alert($(window).height())}); i'm getting landscape view screen height value in portrait view. If i use requirejs i'm facing this issue... @phari – Sathya May 15 '15 at 09:55