Answer the question
In order to leave comments, you need to log in
1 condition works always and another only 1 time after page loading. Why?
Hello .
$(function(){
var widthBody = $("body").width();
if (widthBody >= 1200) {
$(window).scroll(function(){
var winTop = $(window).scrollTop();
if(winTop >= 30){
$("header").addClass("fixed-header");
}else{
$("header").removeClass("fixed-header");
}
});
}
});
Answer the question
In order to leave comments, you need to log in
you need to set another condition, like this
$(window).on('resize', function(){ like this
and then write like this:
$(window).on('resize', function(){
if($( window).width() < 640){
and what should happen !
but it's better to write $(window).on('load resize', function(){
as this should work not only on window change but also on load here
is a demo : https://codepen.io/topicstarter/pen/aGxpjg
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question