JavaScript Why is this difference in calculations? JQuery

i have this site:

link

There is a difference when you call function in document.ready calculation or resize function

There is a white border when the page loads calculation is not correct ...

enter image description here

$( document ).ready(function() {
    var windowsize = $(window).outerWidth();   
    var stanga= jQuery('#secondary').outerWidth();
    console.log('stanga:',stanga);
    var dreapta= jQuery('.right').outerWidth();
    console.log('dreapta:',dreapta);
    var contentwh=windowsize-stanga-dreapta;
    console.log('total:',contentwh);
    $('.navbar-fixed-top').css('width',contentwh);
    $('#main-content').css('width',contentwh);
    $('.continut').css('width',contentwh);

    $(window).on('resize',function(){
        var windowsize = $(window).outerWidth();   
        var stanga= jQuery('#secondary').outerWidth();
        console.log('stanga-resize:',stanga);
        var dreapta= jQuery('.right').outerWidth();
        console.log('dreapta-resize:',dreapta);
        var contentwh=windowsize-stanga-dreapta;
        console.log('total-resize:',contentwh);
        $('.navbar-fixed-top').css('width',contentwh);
        $('#main-content').css('width',contentwh);
        $('.continut').css('width',contentwh);
    }
});

Basically I used the same code and document.ready but also according to resize and unfortunately goes.

I did manual calculation on a 1366 px and ought to get a 669px width (good value) and I am 657px sites.

Does anyone know why this difference appears to 12px?

Thanks in advance!

Answer:1

You must be using Windows as OS aren't you?

The problem is that on load, you have a scrollbar.So when you are making you calculs, some element have a smaller width. Later, the scrollbar dispear and the white gap appear.

Quick fix would be to add overflow:hidden on the body then make your calculs. Afterward, you can remove the overflow hidden.

Note that the problem also appear when you resize the window below a certain height.

Answer:2

-edit

The issue lies with the .right node max-width property disabling this causes the page to load the dimensions correctly however the algorithm with the node resizing is not being run correctly on document ready. The page loads correctly after re-sizing the page.

My best guess for this next issue is that the OP did not provide enough code to fully diagnose his issue; but, i am positive that the code on ready is not executing correctly. Run each variable in console and edit your question to provide the answers please.

Onload values:

window: 1903
custom2.js:89 
stanga: 260
custom2.js:91 
dreapta: 609
custom2.js:93 
total: 1034

After resize:

window: 1918
custom2.js:156 
stanga-resize: 260
custom2.js:158 
dreapta-resize: 614
custom2.js:160 
total-resize: 1044
custom2.js:154 
window: 1920
custom2.js:156 
stanga-resize: 260
custom2.js:158 
dreapta-resize: 614
custom2.js:160 
total-resize: 1046

Your resize event is being triggered twice, thats a problem of its own, but eventually it resolves the correct values.

Answer:3

Below is my code for the directive cabinet and my two controllers CabinetThumbnails,ModalCtrl. Based on my requirement i am using the directive cabinet and the CabinetThumbnails to render couple of ...

Below is my code for the directive cabinet and my two controllers CabinetThumbnails,ModalCtrl. Based on my requirement i am using the directive cabinet and the CabinetThumbnails to render couple of ...

Are there any approaches when using both immutable.js and redux-form that don't require calling .toJS()? I can see the suggested approach on this issue is to call .toJS() on the Map object before ...

Are there any approaches when using both immutable.js and redux-form that don't require calling .toJS()? I can see the suggested approach on this issue is to call .toJS() on the Map object before ...

  1. redux form immutable initial values
  2. redux-form/immutable field
  3. redux form immutable js
  4. redux-form immutable change
  5. redux form immutable props
  6. redux-form/immutable typescript
  7. redux form immutable fieldarray
  8. redux-form-immutable npm
  9. react redux form immutable
  10. react-redux-form/lib/immutable
  11. redux-form immutable values

So when I execute this code, it adds a space between names[i] and the string? var names = ["Bob", "Daniel", "John", "Jimmy", "Joseph"] for (var i = 0; i < names.length; i ++) { console.log("...

So when I execute this code, it adds a space between names[i] and the string? var names = ["Bob", "Daniel", "John", "Jimmy", "Joseph"] for (var i = 0; i < names.length; i ++) { console.log("...

  1. code adding space
  2. code for adding space in html
  3. html code for adding space between lines
  4. html code for adding space between images

I have inherited legacy code that invokes a Javascript in external file for a link action. Below is a snippet of the JS function function webaction(){ $.ajax({ url:contextpath + '/docheck.html' ...

I have inherited legacy code that invokes a Javascript in external file for a link action. Below is a snippet of the JS function function webaction(){ $.ajax({ url:contextpath + '/docheck.html' ...