Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8416917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:54:06+00:00 2026-06-10T01:54:06+00:00

It’s simple, though I’m having trouble. Multiple rows of an element with the same

  • 0

It’s simple, though I’m having trouble. Multiple rows of an element with the same class (.proj) on the page. Each takes 100% width. I want the div.proj that is within 200 pixels of the top of the window to have a class .focused, and otherwise, if it isn’t near the top, to have the class .default. The problem I’m having is singling out the one element.

This is where I am at this point, but it finds all elements .proj instead of just the one that I’m looking for. This is what I have so far, which isn’t really working at all at this point.

$(document).scroll(function(){
    var proj = $('.proj'),
        top = proj.offset().top - $(document).scrollTop();
    if (top < 200 && !proj.is('.default')){
        $(proj).removeClass('focused').addClass('default');
    }
    if (top > 200 && proj.is('.default')){
        $(proj).removeClass('default').addclass('focused');
    }  
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:54:07+00:00Added an answer on June 10, 2026 at 1:54 am

    My example works for every element of class .proj within the 200px range. For singling out a single element, it will work if your elements are of height >= 200px.
    If not you should tell us which is the criterion to “single out” a single element (f.ex. the topmost?)
    In the example the widths are not 100% but the concept is clear I hope

    ​$(window).scroll(checkScroll);
    
    function checkScroll()
    {
        $(".proj").each(function(i,e) {
                var tp = $(e).offset().top - $(document).scrollTop();
                $(e).toggleClass("focused",tp<200).toggleClass("default",tp>=200);
        });
    }​​​​
    

    Check JSFiddle at: http://jsfiddle.net/hnYnS/

    Check also http://jsfiddle.net/hnYnS/2/ for a different approach that uses 100% width and checks range between 0 and 200px.

    $(window).scroll(checkScroll);  
    function checkScroll()
    {
        $(".proj").each(function(i,e) {
                var tp = $(e).offset().top - $(document).scrollTop();
                var isOk = tp<200 && tp>=0;
                $(e).toggleClass("focused",isOk).toggleClass("default",!isOk);
            });
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am doing a simple coin flipping experiment for class that involves flipping a
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.