Hi,
I created a slider that half way works. If I click on the left arrow then the images rotates nicely, but when I click on the right arrow that is where the problem comes in. When I click on it, it rotates to the second image but after that it goes wrong.
Here is the js
- $(".nav_arrows").click(function(){
- $direction1 = ($(this).hasClass("left-arrow") ? "left" : "right");
- var activeBanner1 = 100;
-
-
-
-
- if($direction1 == "right"){
-
- $(".inactive_banner").css("left","100%").show();
- activeBanner1 = -100;
- if($(".active_banner").next().length < 1){
- $(".banner_wrapper").eq(0).animate({"left":0+"%","opacity":1}, 500,function(){
- $(this).addClass("active_banner").removeClass("inactive_banner");
- });
- }else{
- $(".active_banner").next().animate({"left":0+"%","opacity":1}, 500,function(){
- $(this).addClass("active_banner").removeClass("inactive_banner");
- });
- }
-
-
-
-
-
- }else{ //left
- $(".inactive_banner").css("left","-100%").show().fadeTo(250, 0);
- if($(".active_banner").prev().length < 1){
- $(".banner_wrapper").eq($(".banner_wrapper").length-1).animate({"left":0+"%","opacity":1}, 500,function(){
- $(this).addClass("active_banner").removeClass("inactive_banner");
- });
- }else{
- $(".active_banner").prev().animate({"left":0+"%","opacity":1}, 500,function(){
- $(this).addClass("active_banner").removeClass("inactive_banner");
- });
- }
- }
-
- $(".active_banner").animate({"left":activeBanner1+"%","opacity":0}, 500,function(){
- $(this).addClass("inactive_banner").removeClass("active_banner");
- });
-
-
- });
-
My HTML
My CSS
- .banner_wrapper img {
- position: absolute;
- }
- .banner_wrapper .relative {
- width: 100%;
- height: 100%;
- position: relative;
- }
- .bgwidth {
- /* width: 100%; */
- }
- .bgheight {
- display: block;
- height: 100%;
- margin: 0 auto;
- }
-
- .right-arrow {
- background: none repeat scroll 0 0 black;
- position: absolute;
- right: 9%;
- top: 37%;
- }
-
- .right-arrow img{
- position: relative;
- }
-
- .left-arrow {
- background: none repeat scroll 0 0 black;
- left: 8%;
- position: absolute;
- top: 37%;
- z-index: 1;
- }
-
- .left-arrow img{
- position: relative;
- }
Here is a jsfiddle:
JSFIDDLE