Reputation: 151
Trying to check the height on the window (everytime the window re-size), if that is smaller than < 540px, add a css on a class. But why is it not working? something wrong with my jquery??
$( window ).resize(function() {
var windowh = $(window).height();
if (windowh < 540 ) {
$(".theclass").css('height', '200px');
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Upvotes: 0
Views: 66
Reputation: 899
For your question have a two way solutions
with CSS
/* OLD CSS*/
.theclass {
text-align: right;
background: lightgray;
}
/* Solution*/
@media (max-height: 540px) {
.theclass {
height: 200px;
}
}
<div class="theclass">
Full Screen View ↑
</div>
With JS
$( window ).on('load resize',function() { //<-- Change to load,resize
var windowh = $(window).height();
if (windowh < 540 ) {
$(".theclass").css('height', '200px');
}
});//<-- You forgot close `});`
/* OLD CSS*/
.theclass {
text-align: right;
background: lightgray;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="theclass">
Full Screen View ↑
</div>
Upvotes: 4