Hello, I am new to JS, so perhaps the question will seem trivial, but I can not understand why the results of arithmetic calculations in JS are approximate. There is a need to calculate the width of the window and the scroll bar, and then when the scroll bar disappears, move the block to the left to the width of the scroll bar. In general, there is a code
var body_width = ($(window).width() / 2); $('.head_text').css({'position': 'relative', 'left': - (getScrollbarWidth()/2)}); but the result in the browser is not expected, the block is additionally shifted by a few more pixels. With what it can be connected? Thank!
UPD: Thank you all, everything turned out to be simpler, I did not take into account the initial shift of the blocks, it's not about JS. I managed to implement the correct version of hiding the scrollbar without content bias as follows http://jsfiddle.net/Romanzhivo/33pw51hc/7/ I would be grateful for a less cumbersome and more elegant solution.