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 div parent
while position above given top-offset y.

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

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -