I have problem with my jquery code. Problem is that the code goes gradually and when adding a class night_day immediately starts another if. How can I fix it? Thanks for the answers.
$(document).ready(function(){
$( "#light_switch" ).click(function() {
if ( $( this ).hasClass( "day_night" ) ) {
$(".logo").css("background-image", "url('img/CH_logo_web_white.png')");
$("body").css("background-color", "#374356");
$("body").css("color", "#8c8c8c");
$(".info h2").css("color", "#d1d1d1");
$(".shoot-left .desc h2").css("color", "#8c8c8c");
$(".shoot-right .desc h2").css("color", "#8c8c8c");
$("#footer p").css("color", "#d1d1d1");
$("#light_switch").removeClass("day_night").addClass("night_day");
}
if ( $( this ).hasClass( "night_day" ) ) {
$(".logo").css("background-image", "url('img/CH_logo_web_white.png')");
$("body").css("background-color", "#FFFFFF");
$("body").css("color", "#8c8c8c");
$(".info h2").css("color", "#d1d1d1");
$(".shoot-left .desc h2").css("color", "#404040");
$(".shoot-right .desc h2").css("color", "#404040");
$("#footer p").css("color", "#8c8c8c");
$("#light_switch").removeClass("night_day").addClass("day_night");
}
});
});
<div id="light_switch" class="day_night"></div>
Aucun commentaire:
Enregistrer un commentaire