admin管理员组文章数量:1315481
I add this pagination.js script when you change page 1,2,3,4,5
$(document).ready(function(){
var $listItems = $('.pagination li');
$listItems.click(function(){
$listItems.removeClass('active');
$(this).addClass('active');
});
});
I want add a function to prev and next arrow of carrousel, when your click on the arrow, the function remove class .active of the previous page and add the .class active in the next page.
Arrow controls code:
<div class="arrowPosition2">
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left arrowSlider"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right arrowSlider"></span>
</a>
</div>
My english is not very good, you can see this screenshot:
Thanks a lot.
EDIT:
<div class="arrowPosition2">
<a id="arrowPrev" class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left arrowSlider"></span>
</a>
<a id="arrowNext" class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right arrowSlider"></span>
</a>
</div>
$(document).ready(function(){
var $listItems = $('.pagination li');
var $arrowItems = $('.arrowPosition2 a');
$listItems.click(function(){
$listItems.removeClass('active');
$(this).addClass('active');
var activeLink=$(this);
});
$('#arrowPrev').on('click',function(){
var $activeLi=$('.pagination').find("li.active");
$activeLi.removeClass('active');
if($activeLi.prev()!=null && $activeLi.prev()!=undefined ){
$activeLi.prev().addClass('active');
}else{
$('.pagination').find("li:last").addClass("active")
}
});
$('#arrowNext').on('click',function(){
var $activeLi=$('.pagination').find("li.active");
$activeLi.removeClass('active');
if($activeLi.next()!=null && $activeLi.next()!=undefined ){
$activeLi.next().addClass('active');
}else{
$('.pagination').find("li:last").addClass("active")
}
});
});
I add this pagination.js script when you change page 1,2,3,4,5
$(document).ready(function(){
var $listItems = $('.pagination li');
$listItems.click(function(){
$listItems.removeClass('active');
$(this).addClass('active');
});
});
I want add a function to prev and next arrow of carrousel, when your click on the arrow, the function remove class .active of the previous page and add the .class active in the next page.
Arrow controls code:
<div class="arrowPosition2">
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left arrowSlider"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right arrowSlider"></span>
</a>
</div>
My english is not very good, you can see this screenshot:
Thanks a lot.
EDIT:
<div class="arrowPosition2">
<a id="arrowPrev" class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left arrowSlider"></span>
</a>
<a id="arrowNext" class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right arrowSlider"></span>
</a>
</div>
$(document).ready(function(){
var $listItems = $('.pagination li');
var $arrowItems = $('.arrowPosition2 a');
$listItems.click(function(){
$listItems.removeClass('active');
$(this).addClass('active');
var activeLink=$(this);
});
$('#arrowPrev').on('click',function(){
var $activeLi=$('.pagination').find("li.active");
$activeLi.removeClass('active');
if($activeLi.prev()!=null && $activeLi.prev()!=undefined ){
$activeLi.prev().addClass('active');
}else{
$('.pagination').find("li:last").addClass("active")
}
});
$('#arrowNext').on('click',function(){
var $activeLi=$('.pagination').find("li.active");
$activeLi.removeClass('active');
if($activeLi.next()!=null && $activeLi.next()!=undefined ){
$activeLi.next().addClass('active');
}else{
$('.pagination').find("li:last").addClass("active")
}
});
});
Share
Improve this question
edited Sep 15, 2019 at 15:05
Glorfindel
22.7k13 gold badges89 silver badges118 bronze badges
asked Apr 28, 2014 at 7:36
Antonio MoralesAntonio Morales
1,0742 gold badges17 silver badges39 bronze badges
2
- 1 can u write your code in feddle jsfiddle – Gaurang s Commented Apr 28, 2014 at 7:38
- Possible duplicate of Call next and prev function of jquery jCarousel – Batu.Khan Commented Apr 28, 2014 at 7:42
5 Answers
Reset to default 2Plz change if condition
if($activeLi.next().length>0 ){
$activeLi.next().addClass('active');
}else{
$('.pagination').find("li:first").addClass("active")
}
i think this will help you
var activeLink;
$(document).ready(function(){
var $listItems = $('.pagination li');
$listItems.click(function(){
$listItems.removeClass('active');
$(this).addClass('active');
var activeLink=$(this);//// store in variable and do work on pev next btn
});
});
$('#Arrow').on('click',function(){
var $activeLi=$('.pagination').find("li.active");
$activeLi.removeClass('active');
if($activeLi.prev()!=null && $activeLi.prev()!=undefined ){
$activeLi.prev()..addClass('active');
}else{
$('.pagination').find("li:last").addClass("active")
}
});
$('#NEXT_ARROW_ID').on('click',function(){
var $activeLi=$('.pagination').find("li.active");
$activeLi.removeClass('active');
if($activeLi.next()!=null && $activeLi.next()!=undefined ){
$activeLi.next().addClass('active');
}else{
$('.pagination').find("li:first").addClass("active")
}
});
this is your : pagination.js
$(document).ready(function(){
var $listItems = $('.pagination li');
var $arrowItems = $('.arrowPosition2 a');
$listItems.click(function(){
$listItems.removeClass('active');
$(this).addClass('active');
var activeLink=$(this);
});
$('#arrowPrev').on('click',function(){
var $activeLi=$('.pagination').find("li.active");
$activeLi.removeClass('active');
if($activeLi.prev().length>0 ){
$activeLi.prev().addClass('active');
}else{
$('.pagination').find("li:last").addClass("active")
}
});
$('#arrowNext').on('click',function(){
var $activeLi=$('.pagination').find("li.active");
$activeLi.removeClass('active');
if($activeLi.next().length>0){
$activeLi.next().addClass('active');
}else{
$('.pagination').find("li:first").addClass("active")
}
});
});
本文标签: javascriptAdd and remove pagination active class when I click in next and prev arrowsStack Overflow
版权声明:本文标题:javascript - Add and remove pagination .active class when I click in next and prev arrows - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741949088a2406600.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论