【问题标题】:Jquery getting position().top of div with :not(.class)Jquery 使用 :not(.class) 获取 div 的 position().top
【发布时间】:2014-10-11 14:09:18
【问题描述】:

我在使用时遇到问题

:not(.disabled)

在类选择器中。用了之后就进不去了

$(this).position().top

这里是代码

    $('.game:not(.disabled)').bind('click', function(){
    // Note, there is also scrollToX and scrollToY methods if you only
    // want to scroll in one dimension
    $('.game').removeClass('active');
    $(this).addClass('active');
    var newgame = $(this).attr('data-href');
    theGame = newgame;
    console.log('EVENT: [CHANGED] ['+theGame+']');

    var y = $(this).position().top;
    console.log('EVENT: [SCROLLTO]['+0+' : '+y+']');
    console.log(y);

    api.scrollTo(0, y);
        return false;
    });

当我删除 :not(.disabled) 时,它可以正常工作,并且 'y' 坐标也可以正常使用..

我该如何解决这个问题?

【问题讨论】:

    标签: javascript jquery css position css-position


    【解决方案1】:

    试试这个:

    jsFiddle Demo

    $('.game').not('.disabled').on('click', function(){
    

    记得使用 .on 而不是 .bind(现在有几个版本的 jQuery...)

    【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签