I want to call a JavaScript function that checks the width of the window every time it loads and also every time the screen is re-sized. The reason for this is i dont want a function to be used when the screen size gets too small e.g. mobile size.
Can this be done?
Ive tried doing something like this
window.onload = function () {
if (window.onload.innerWidth > 991 || window.onresize.innerWidth > 991) {
var maxHeight = 0;
setTimeout(function () {
maxHeight = 0;
$(".menu> div").each(function () {
var thisHeight = parseInt($(this).css("height").toString().replace("px", ""));
if (thisHeight > maxHeight) {
maxHeight = thisHeight;
}
});
$(".menu> div").css("height", maxHeight.toString() + "px");
$(".menu").sortable({
handle: "h3",
placeholder: {
element: function (currentItem) {
return $("<div class='col-md-4 placeholderBlock' style='height:" + (maxHeight).toString() + "px; '></div>")[0];
},
update: function (container, p) {
return;
}
}
});
$(".menu").disableSelection();
$(".widget").each(function () {
$(this).click(function () {
enableDisableWidget($(this));
});
});
setInterval(function () {
var menu= { items: [] };
$(".menu> div").each(function () {
menu.items.push(
{
classes: "." + $(this).attr("class").replace(/\ /g, ' ')
}
);
});
$(".hiddenField_dashboardLayout").val(JSON.stringify(dashboardItems));
}, 500);
}, 2000);
}
}