【问题标题】:jQuery SlideShow of Reviews if Class Exists如果类存在,则评论的 jQuery 幻灯片
【发布时间】:2011-08-15 11:53:29
【问题描述】:

我已经在“helpfulreviews”类的表格中动态创建了评论。我想获取这些表格并基本上隐藏除一个之外的所有表格,并在一段时间后使用 jQuery 自动滑入下一个表格

这里有三条评论,我希望一个显示并在大约 10 秒后滑入另一条评论,然后滑入第三条评论,然后旋转回到开头。我已经简化了示例:

<table width="100%" border="1" cellspacing="0" cellpadding="0" class="helpfulreviews">
  <tbody>
     <tr> 
        <td>MY FIRST REVIEW GOES HERE<br>Terrible Product</td>
     </tr>
  </tbody>
</table>
<table width="100%" border="1" cellspacing="0" cellpadding="0" class="helpfulreviews">
  <tbody>
     <tr> 
        <td>MY SECOND REVIEW GOES HERE<br>Great Product you have here</td>
     </tr>
  </tbody>
</table>
<table width="100%" border="1" cellspacing="0" cellpadding="0" class="helpfulreviews">
  <tbody>
     <tr> 
        <td>MY THIRD REVIEW GOES HERE<br>This is an awesome product</td>
     </tr>
  </tbody>
</table>

其中一张表的完整代码:

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="helpfulreviews">
        <tbody><tr> 
          <td width="1%">&nbsp;</td>
          <td width="99%"> 
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="colors_descriptionbox">
              <tbody><tr> 
                <td width="1px" valign="top"><img src="/v/vspfiles/templates/90/images/RBox_Border_Left_Top.gif"></td>
                <td width="100%" valign="top" background="/v/vspfiles/templates/90/images/DBox_Border_Top.gif"><img src="/v/vspfiles/templates/90/images/clear1x1.gif" width="1" height="1"></td>
                <td width="1px" valign="top"><img src="/v/vspfiles/templates/90/images/DBox_Border_Right_Top.gif"></td>
              </tr>
              <tr> 
                <td width="1px" background="/v/vspfiles/templates/90/images/DBox_Border_Left.gif"><img src="/v/vspfiles/templates/90/images/clear1x1.gif" width="1" height="1"></td>
                <td width="100%" valign="top"> 
                  <table width="100%" cellpadding="0" cellspacing="0" border="0">
                    <tbody><tr> 
                      <td><b><img src="/v/vspfiles/templates/90/images/star5.gif"><br> 
                        Great Product</b> </td>
                      <td align="right"><i>April 28, 2011</i></td>
                    </tr>
                    <tr> 
                      <td><i><span class="PageText_L510n">Reviewer</span>: 
                        <span class="PageText_L512n">Anonymous Person</span>

                        </i><br><br></td>
                      <td align="right">&nbsp;</td>
                    </tr>
                  </tbody></table>
                  I used this product and it was great<br>
                  <br>
                  <span class="PageText_L514n"><span id="helpful"></span></span> <a href="/reviewhelpful.asp?ProductCode=TRU%2DGDM49&amp;ID=12&amp;yes=yes"><img src="/v/vspfiles/templates/90/images/buttons/btn_reviews_yes.gif" align="absmiddle" border="0"></a> 
                  <a href="/reviewhelpful.asp?ProductCode=TRU%2DGDM49&amp;ID=12&amp;yes=no"><img src="/v/vspfiles/templates/90/images/buttons/btn_reviews_no.gif" align="absmiddle" border="0"></a> 

                </td>
                <td width="1px" background="/v/vspfiles/templates/90/images/DBox_Border_Right.gif"><img src="/v/vspfiles/templates/90/images/clear1x1.gif" width="1" height="1"></td>
              </tr><tr> 
                <td width="1px" valign="top"><img src="/v/vspfiles/templates/90/images/DBox_Border_Left_Bottom.gif"></td>
                <td width="100%" valign="top" background="/v/vspfiles/templates/90/images/DBox_Border_Bottom.gif"><img src="/v/vspfiles/templates/90/images/clear1x1.gif" width="1" height="1"></td>
                <td width="1px" valign="top"><img src="/v/vspfiles/templates/90/images/DBox_Border_Right_Bottom.gif"></td>
              </tr>
            </tbody></table>
          </td>
        </tr>
      </tbody></table>  

【问题讨论】:

  • 你有帮助的评论课有什么重要的吗? (我在搞乱你的代码,如果它很重要,我想包含它)如果是这样,你可以发布它吗?
  • @Thomas-Shields 是的,我有帮助的评论类里面有很多东西,我已经更新了上面的代码!
  • 好问题顺便说一句。终于得到了我的答案,并且在制作过程中学到了很多东西。谢谢!

标签: jquery slideshow slide


【解决方案1】:

抱歉耽搁了。这是一个工作示例。显然,您可以调整大小和内容以适应您的目的。这个想法是用overflow:hidden将表格包装在一个容器div中并根据需要偏移它们(即,第一个表格被定位以填充div,第二个有margin-left等于容器的宽度,第三个的边距左边是宽度的两倍,等等)

 <style type="text/css">
 .helpfulreviews
 {
     width:100%;
     height:100%;
       position:absolute; 
 }
 </style>
 <div style="width:400px; height:50px; overflow:hidden; position:relative;" id="sliderContain">
 <table width="100%" height="100%" border="1" cellspacing="0" cellpadding="0" class="helpfulreviews">
   <tbody>
        <tr>
                 <td>MY FIRST REVIEW GOES HERE<br>Terrible Product</td>
                      </tr>
                        </tbody></table>
<table width="100%" height="100%" border="1" cellspacing="0" cellpadding="0" class="helpfulreviews" >  
                        <tbody>  
                           <tr>     
                               <td>MY SECOND REVIEW GOES HERE<br>Great Product you have here</td>   
                                 </tr> 
                                  </tbody></table>
<table width="100%" height="100%" border="1" cellspacing="0" cellpadding="0" class="helpfulreviews" >  <tbody>     <tr>         <td>MY THIRD REVIEW GOES HERE<br>This is an awesome product</td>     </tr>  </tbody></table>
 </div>
 <script type="text/ecmascript">
     $(document).ready(function () {
         var w = 300; //set your width here
         var h = 50; //set your height here
         var d = 3000;  //set your delay here
         var n = $(".helpfulreviews").length;
         if(n>1){
          var t = window.setTimeout(slideTable, d);
          $("#sliderContain").css("width", w + "px");
          $("#sliderContain").css("height", h + "px");
          var i = h;
          $(".helpfulreviews").each(function (index) {
              i = h * index;
              $(this).css("top", i + "px");
          });
         }
         function slideTable() {
             $(".helpfulreviews").each(function (index) {
                 if ($(this).css("top") == (1 - n) * h + "px") { //checks if we need to cycle them around
                     $(this).css("top", h + "px");
                 }
             });
             var a2l = "-=" + h + "px";
             $(".helpfulreviews").animate({
                 top: a2l
             }, 300, function () {
                 slideTable();
             }).delay(d);
         };
     });
 </script>

编辑:我更改了代码以基于定义一些变量来动态更改表和值和内容;这样您就不必在每次更改评论大小时都更改一堆值。

【讨论】:

  • 非常好。我试图让它与我所拥有的 HERE 一起正常工作。这些表将被动态创建,因此我无法指定将有多少个表。您会注意到右侧的评论。
  • 哦,再想一想,你不应该指定表的数量......只要它们有.helpfulreviews 类,我应该能够从 jQuery 中计算它们。那里。已更新 - 希望对您有所帮助。
  • 太棒了,我可以让它从下到上而不是从右到左吗?
  • 是的,把左边的边距换成顶部的边距。一分钟,我会更新它。
  • 见鬼,这比我想象的要难。问题是tables 是块元素,因此会创建自己的换行符,因此很难在它们上设置 margin-top。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-21
  • 2013-04-11
  • 2014-04-02
  • 2011-01-01
相关资源
最近更新 更多