Reputation: 23
Currently, this script only works when I adjust the window - I'd like it to work on load but do not know-how. I think this is simple but I can't figure it out.
$(window).on('resize', function() {
if($(window).height() > 300) {
$('.card').addClass('hover');
$('.card').removeClass('no');
}else{
$('.card').addClass('no');
$('.card').removeClass('hover');
}
})
Upvotes: 0
Views: 138
Reputation: 2049
Just create a function and execute it onload and as a event listener of the onresize
function resizeHandler() {
if ($(window).height() > 300) {
$('.card').addClass('hover');
$('.card').removeClass('no');
} else {
$('.card').addClass('no');
$('.card').removeClass('hover');
}
}
$(window).on('resize', resizeHandler);
$(document).ready(resizeHandler);
Upvotes: 1