I want to make the block width and the offset value calculated dynamically, and not static. I understand that you need to use resize, but I do not understand how it can be implemented. Here's what I got:

$(function(){ var exp = $("#tile_shop2"); var expB = exp.width(); var expW = $(window).width(); var offset = exp.offset(); exp.css("margin-left", -((expB-expW)/2+offset.left)); }); 

    1 answer 1

     $( document ).ready(function() { resize(); $(window).on("resize", resize); }); function resize(){ var exp = $("#tile_shop2"); var expB = exp.width(); var expW = $(window).width(); var offset = exp.offset(); exp.css("margin-left", -((expB-expW)/2+offset.left)); } 
    • one
      Would you take this expression to a separate function, at least ... - VenZell
    • This was done by chance. Thank you) - Mihanik71