首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JQuery- animate()仅在单击时有效一次

JQuery- animate()仅在单击时有效一次
EN

Stack Overflow用户
提问于 2017-07-31 03:42:15
回答 1查看 49关注 0票数 0

我使用了两个锚标签(#trendingnexticon和#trendingpreviousicon)来移动容器的内容,当我点击标签时,内容会完美地向右或向左移动,但它只移动一次。当我再次点击时,它不会移动!有什么建议吗?

Javascript:

代码语言:javascript
复制
 $(document).ready(function(){
        $("#trendingnexticon").on('click' ,function(){
            $("#trendingtable").animate({right: '800px'});
        });
     });


    $(document).ready(function(){
        $("#trendingpreviousicon").on('click' ,function(){
            $("#trendingtable").animate({left: '100px'});
        });
    });

HTML:

代码语言:javascript
复制
<div id="trendingdiv" class="" style="overflow-x:scroll; overflow: 
    hidden;">
      <table id="trendingtable" class="table" style="position:relative;">
        <a id="trendingpreviousicon" style="cursor:pointer; margin-top: 
    62px; position:absolute; z-index:1;" class="previous round">&#8249;</a>
        <a id="trendingnexticon" style="cursor:pointer; margin-left: 1250px; 
    margin-top: 62px; position:absolute; z-index:1;" class="next 
    round">&#8250;</a>
        <tr>
        <?php while ($tsingers = mysqli_fetch_assoc($tsingersquery)): ?>
          <td>
              <div class="media" style="border: 1px solid #e6e6e6; 
    width:400px; padding: 0px;">
              <img src="images/<?=$tsingers['image'];?>" alt="<?
    =$tsingers['name'];?>"
              class="pull-left img-responsive" style="width: 200px; height: 
    150px;" id="artistimg">
              <div id="trendingmediabody" class="media-body">
                <p id="trendingname" style="font-size:14px; font-weight: 
    bolder;"><?=$tsingers['name'];?></p>
                <p id="trendingcategory" style="font-size:12px; font-weight: 
    bolder;"><?=$tsingers['category'];?></p></br></br>
              </div>
            </div>
          </td>
        <?php endwhile; ?>
        </tr>
      </table>
    </div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-31 03:48:36

通过执行$("#trendingtable").animate({right: '800px'});,您实际上是在说“动画元素,直到它相对于其父元素的右侧位置为800px。”执行此操作两次不会有任何效果。如果你想让它移动多次,你可以使用像这样的相对移动

代码语言:javascript
复制
$("#trendingtable").animate({right: '+=800px'});

请参阅此处的文档:http://api.jquery.com/animate/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45403968

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档