Jon
Jon

Reputation: 1347

Pjax/Ajax fragment returning width/offsetWidth of 0 on load

Running into a difficult bug with Pjax fragments on the following site:

https://dl.dropboxusercontent.com/u/65752410/map.html

Currently, clicking on the "schedule" and "map" links in the nav will load page fragments via Pjax along with some conditional javascript, courtesy of requirejs.

On the "map" page, the first page load will calculate the width of each element with a class of .side-panel correctly. However, subsequent loads will return a width of 0, despite the fact that the selected element is present in the DOM when the width is queried.

To reproduce the bug:

  1. wait until the map loads
  2. click the "schedule" link to load the schedule page
  3. click the "map" link to load the map page. The width of each .side_panel will be logged as 0.

If you keep the console open during this test, you'll see that the proper width is logged on page load, the schedule page is dynamically loaded in the second step, and the map page is then loaded with the .side_panel elements in the DOM, but returning a width of 0.

Upvotes: 0

Views: 690

Answers (1)

kalley
kalley

Reputation: 18462

If you look at the console, the panel div doesn't have an offsetParent, which means it's not yet been inserted into the DOM, which would mean that the width will be 0.

Upvotes: 6

Related Questions