ページのスライダーで.activeクラスを切り替えてページネーションを作成しようとしています。
私は現在使用しています:
jQuery(window).load(function(){
if (jQuery("#image1").hasClass("crsl-active")){
jQuery(".pager1").toggleClass("active");
}
});
スライダーが2番目のdivに移動すると、.crsl-activeクラスは次のdivに移動しますが、.pager1の.activeクラスは削除されません。どんな助けでも大歓迎です。
回答:
回答№1は1最初にすべての「アクティブ」を削除してから、ルールを適用します。
$(".active").each(function(){
$(this).removeClass("active");
});
if (jQuery("#image1").hasClass("crsl-active")){
jQuery(".pager1").toggleClass("active");
}
最初のルールは次のように記述できます。
$(".active").removeClass("active");
でも個人的にはあまり好きではありません。