【问题标题】:Jquery content slider not workingJquery 内容滑块不起作用
【发布时间】:2013-09-11 06:12:24
【问题描述】:

我正在尝试使用 jquery 创建内容滑块。

  1. 默认情况下,滑块应显示第一个内容

  2. 在“下一个”单击时,我想显示下一个内容(在我的 div(类名:sp)内),该内容应该显示为从右向左滑动,并且

  3. 在“上一个”点击时,我想显示上一个内容,应该显示从右向左滑动

我已经设法开发了以下代码,但它根本不起作用。

你能告诉我错误在哪里吗?

你也可以在这里查看我的代码:http://jsfiddle.net/zLGQJ/1/

HTML

<div id="button-previous"><a>prev</a></div><div id="button-next"><a>next</a></div>

<div class="featured_Content">

<div class="sp">
  <div><h2>Demo Title 1</h2></div>
 <div style="float:right;"><img src="image.jpg" width="250" height="150" /></div>
  <div style="float:right;">My text</div>
  <div style="clear:both;"></div> 
</div>

<div class="sp">
  <div><h2>Demo Title 1</h2></div>
 <div style="float:right;"><img src="image.jpg" width="250" height="150" /></div>
  <div style="float:right;">My text</div>
  <div style="clear:both;"></div> 
</div>

<div class="sp">
  <div><h2>Demo Title 1</h2></div>
 <div style="float:right;"><img src="image.jpg" width="250" height="150" /></div>
  <div style="float:right;">My text</div>
  <div style="clear:both;"></div> 
</div>

</div>  

CSS:

.featured_Content{
  width:500px;
  height:200px; 
  position:relative;

 } 
.sp {width:500px; height:200px; position:absolute;}

jquery:

 $(document).ready(function(){
 $('.sp').first().addClass('active');
 $('.sp').hide();    
 $('.active').show();


 $('#button-next').click(function(){

   $('.active').removeClass('active').addClass('oldActive');    

    if ( $('.oldActive').is(':last-child')) {
    $('.sp').first().addClass('active');
    }
    else{
    $('.oldActive').next().addClass('active');
    }

    $('.oldActive').removeClass('oldActive');
    $('.sp').fadeOut();
    $('.active').show("slide", { direction: "left" }, 1000);


});

$('#button-previous').click(function(){
$('.active').removeClass('active').addClass('oldActive');   

   if ( $('.oldActive').is(':first-child')) {

        $('.sp').last().addClass('active');

    }
       else{
 $('.oldActive').prev().addClass('active');
       }
 $('.oldActive').removeClass('oldActive');
 $('.sp').fadeOut();
 $('.active').show("slide", { direction: "left" }, 1000);
 });


});

【问题讨论】:

    标签: jquery jquery-ui-slider


    【解决方案1】:
    $('#button-previous').click(function () {
        $('.active').removeClass('active').addClass('oldActive');
    
        if ($('.oldActive').is(':first-child')) {
    
            $('.sp').last().addClass('active');
    
        } else {
            $('.oldActive').prev().addClass('active');
        }
        $('.oldActive').removeClass('oldActive');
        $('.sp').fadeOut();
        $('.active').show("slide", {
            direction: "right"
        }, 1000);
    });
    

    $('.active').show("slide", {
            direction: "left"
        }, 1000);
    

    是问题所在。

    Fiddle

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-09
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      • 2014-04-22
      • 1970-01-01
      相关资源
      最近更新 更多