positioning - jQuery: get elements above a given 'y' position -
how can jquery, in elegant way?
apply
z
attribute (e.g.: red background) every children of divparent
while position above given top-offsety
.
i've tried in different ways, i'm not happy of them...
know there must short , elegant way it...
since you're saying you've tried few ways, , you're looking more elegant, i'll assume have offset part worked out, , i'll go offset
myself. modify part needed. elegance, create custom selector checking top offset:
$.expr[':'].above = function(obj, index, meta, stack) { return $(obj).offset().top < meta[3]; }
you query such:
$('#myparentdiv').find('div:above(100)').css('background-color', 'red');
of course have been expressed as
$('#myparentdiv div:above(100)').css('background-color', 'red');
or, pointed out in comments
var y = 100; $('#myparentdiv div:above('+y+')').css('background-color', 'red');
Comments
Post a Comment