Why, in the console does this display the browser size after every size change (as expected):
window.onresize = function() {
var width = $(window).width();
console.log(width);
}
But when creating it as a function and calling it, it does not?:
window.onresize = browserResizeAdjustments();
function browserResizeAdjustments() {
var width = $(window).width();
console.log(width);
}
The reason being is I want to run this onload as well, not just when the first browser size change happens.
Final Solution:
<script type="text/javascript">
window.onresize = browserResizeAdjustments;
function browserResizeAdjustments() {
var width = $(window).width();
console.log(width);
}
// This runs it onload
browserResizeAdjustments();
</script>
window.onresize should be a reference to a function, not the result of a function call. Try this:
window.onresize = browserResizeAdjustments;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.