首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用jQuery向右/向左滑动表

问使用jQuery向右/向左滑动表
EN

Stack Overflow用户
提问于 2012-04-03 19:27:46
回答 2查看 5.1K关注 0票数 0

我将通过AJAX获得一个表,jQuery.getJSON依赖于表之前或之后的数据,该表应该向右或向左滑动。我是jQuery的初学者。诺马利,我会用正常的javascript来做,但我想让jQuery。

为了滑动这两个表,我尝试了来自this answer的代码,也尝试了this one。

但这一切都不会滑倒。不知道为什么。

我的下一次尝试是将float:left应用于第一个表并设置width,但在这种特殊情况下,我在填充或边距方面遇到了一些麻烦。可能和我用的模板有关。

然而,我如何能够从右到左和副vesa将新内容滑动到表中呢?

代码语言:javascript
复制
  <div class="content">
    <script type="text/javascript">
function load(url) {
    document.body.style.cursor='wait';
    jQuery.getJSON(url, function(data) {
        document.body.style.cursor='default';
        var html = "";
        var yes=0;
        for(var i=0;i<data['data'].length;i++)
            if(data['data'][i].state)
                yes++;

        var nav=document.getElementsByClassName('quick-nav')[0].getElementsByTagName('a');
        nav[0].href=data['navi']['last'];
        nav[1].href=data['navi']['next'];

        html+='<table class="Status" cellspacing="0">';
        html+='<tr><th style="width:120px;">Name</th><th style="width:120px;">Vorname</th><th>zugesagt</th><th style="width:100px;">&nbsp;</th></tr>';

        for(var i=0;i<data['data'].length;i++) {
            var user=data['data'][i];
            var status=user.state?"ja":"nein";
            html+='<tr class="'+(user.default?'':'un')+'regel"><td>'+user.lastname+'</td><td>'+user.firstname+'</td><td><img src="/images/'+status+'.png" alt="" title="'+status+'"/>'+status+'</td><td class="'+status+'">&nbsp;</td></tr>';
        }

        html+='</table>';

        document.getElementsByClassName('teilnahme-liste')[0].innerHTML+=html;
    });
}
</script>
<div class="quick-nav">
  <a href="/path/10.04.2012" onclick="load(this.href); return false;">&laquo; Woche früher</a>
  <a href="/path/24.04.2012" onclick="load(this.href); return false;" style="float:right;">Woche später &raquo;</a>
</div>
<div class="teilnahme-liste">
    <h2>...</h2>
  <style type="text/css">
.Status img {
    line-height: 1em;
    margin: -4px 0.4em 0 0;
    vertical-align: middle;
}
</style>
  <table class="Status" cellspacing="0">
    <tr>
      <th style="width:120px;">Name</th>
      <th style="width:120px;">Vorname</th>
      <th>zugesagt</th>
      <th style="width:100px;">&nbsp;</th>
    </tr>
    <tr class="regel">
      <td>Mustermann</td>
      <td>Max</td>
      <td><img src="/images/ja.png" alt="" title="ja"/>ja</td>
      <td class="ja">&nbsp;</td>
    </tr>
    <tr class="regel">
      <td>Müller</td>
      <td>Lieschen</td>
      <td><img src="/images/nein.png" alt="" title="nein"/>nein</td>
      <td class="nein">&nbsp;</td>
    </tr>
    <tr class="unregel">
      <td>Schmitt</td>
      <td>Tobias</td>
      <td><img src="/images/ja.png" alt="" title="ja"/>ja</td>
      <td class="ja">&nbsp;</td>
    </tr>
  </table>
</div><input type="submit" name="op" value="Speichern" class="form-submit" />  </div>
</div>
  </div>

    </div></div>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-11 10:10:16

这是我的解决办法。请注意,我使用了德语单词neu=new和alt=old:

代码语言:javascript
复制
var neu=jQuery(jQuery(".Status")[1]);
var alt=jQuery(jQuery(".Status")[0]);
alt.css({ opacity: 1, left: '0px'});
neu.css({ opacity: 1, left: '700px'});
// move the element higher
neu.css("margin-top",(alt[0].offsetTop-neu[0].offsetTop)+"px");

neu.animate({ opacity: 1, left: '0px' }, 400);
alt.animate({ opacity: 0, left: '700px' }, 400, null, function(){
    alt.remove();
    neu.css("margin-top","");
});

我还添加了这一行css:

代码语言:javascript
复制
.Status {
    position:relative;
}
票数 0
EN

Stack Overflow用户

发布于 2012-04-03 21:06:06

像这样的东西怎么样?它只使用CSS和jQuery (没有jQuery UI效果)。

http://jsfiddle.net/u8mkb/3/

代码语言:javascript
复制
$(document).ready(function() {
 $("#btnTest").click(function() {
    $("#state-holder").slideBabySlide(function() {});
 });
});

$.fn.slideBabySlide = function(callback) {
return this.each(function() {
    var $this = $(this);

    $this.animate({ opacity: 0, left: '-700px' }, 200, function() {
        $(this).css("left", 700);

        $("#whatever").show();

        $(this).animate({ opacity: 1, left: '0px' }, 300, function() {

            if ($.isFunction(callback)) callback();
        });
    });
});
};

使用表代替div - http://jsfiddle.net/u8mkb/4/更新​

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

https://stackoverflow.com/questions/10000033

复制
相关文章

相似问题

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