I'm facing an issue with my resize function where the contents within a window change when it reaches a certain width. I'm trying to achieve this same effect on window load but haven't been successful so far. Here's what I've attempted:
Attempt 1
$(window).load(function () {
updateDivsMargins();
$(window).resize(updateDivsMargins);
function updateDivsMargins() {
var windowWidth = $(window).width();
if (windowWidth >= 2560) {
alert("hello im 2560")
$('.1').css('margin-left', '500px');
$('#2').css('margin-right', '-300px');
$('#3').css('margin-left', '550px');
$('#4').css('margin-right', '-28em');
}
}
});
Attempt 2
$(window).on("resize", function () {
var windowWidth = $(window).width();
if (windowWidth >= 2560) {
alert("hello im 2560")
$('.1').css('margin-left', '500px');
$('#2').css('margin-right', '-300px');
$('#3').css('margin-left', '550px');
$('#4').css('margin-right', '-28em');
}
}).resize();
When I resize the page, the changes take effect as expected. However, if the page loads at exactly 2560, the changes are not applied. I'm wondering how I can make these changes apply both on load and resize. What am I missing in the two attempts above that is preventing them from taking effect on load?