gpt4 book ai didi

javascript - Jquery 获取 position().top of div with :not(. class)

转载 作者:太空宇宙 更新时间:2023-11-04 12:48:31 26 4
gpt4 key购买 nike

我在使用

时遇到问题
: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”坐标使用得很好..

我该如何解决这个问题?

最佳答案

试试这个:

jsFiddle Demo

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

请记住使用 .on 而不是 .bind(对于现在的几个 jQuery 版本...)

关于javascript - Jquery 获取 position().top of div with :not(. class),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26315518/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com