2 Replies - 417 Views - Last Post: 20 December 2016 - 07:07 AM

#1 solracp25  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-December 16

Recalculating offset from top

Posted 19 December 2016 - 11:34 PM

I have a function setup that detects the offset from the top -- it's working just fine on load, but when the orientation changes, it won't recalculate. I thought "orientationchange" covered that, but for some reason it doesn't force a new offset. Been at this for a couple days, just can't figure it out ://>


 $(document).ready(function() {
var menu_hdr = $("[id^=table-] .divwrap").offset().top,$window = $(window);
var menu_end_check = $(".table tbody tr:nth-last-child(9)").offset().top,$window = $(window);


$(window).on("scroll resize orientationchange", function stickymenu() {
    var y_scroll_pos = window.pageYOffset;
    var menu_header = menu_hdr;
    var menu_footer_check = menu_end_check; 
    if((y_scroll_pos >= menu_header) && (y_scroll_pos < menu_footer_check)) {

    /* do stuff */

    }

    }); 
    }); 


Is This A Good Question/Topic? 0
  • +

Replies To: Recalculating offset from top

#2 andrewsw  Icon User is online

  • say what now
  • member icon

Reputation: 6410
  • View blog
  • Posts: 25,914
  • Joined: 12-December 12

Re: Recalculating offset from top

Posted 20 December 2016 - 04:44 AM

You need to break it down a little further. Is your event code being executed at all on changing orientation? Add a simple console.log("running.."); into the event to confirm whether it is. You could also considering temporarily splitting to three separate events, just to distinguish between them [although I suppose it should be possible somehow to determine which named event was fired].

If it is running then add a console.log(window.pageYOffset); to confirm its value. IE < 9 requires a workaround for this value, discussed here.

The jQuery docs for orientationchange also has a note about timing. The note discusses the width and height metrics but it may impact the reading of pageYOffset. It suggests the fallback of the resize event.
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2343
  • View blog
  • Posts: 9,400
  • Joined: 03-December 12

Re: Recalculating offset from top

Posted 20 December 2016 - 07:07 AM

That portion should be in a function, then when there is a change detected, it is run again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1