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

  • SEARCH
  • Home
  • 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 9235495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:03:07+00:00 2026-06-18T07:03:07+00:00

I want to know if it’s possible to change my selected li class based

  • 0

I want to know if it’s possible to change my “selected” li class based on the movements of the horizontal scroll. So when you start moving the scroll to the right, the selected li class would change to 2, 3, 4 .. and so on.

Any hints or points to start from are appreciated.

My code:

<div id="scroller">
<ul id="ulscroller">
<li value="1" class="selected">1</li>
<li value="2">2</li>
<li value="3">3</li>
<li value="4">4</li>
<li value="5">5</li>
<li value="6">6</li>
<li value="7">7</li>
<li value="8">8</li>
<li value="9">9</li>
<li value="10">10</li>
<li value="11">11</li>
<li value="12">12</li>
<li value="13">13</li>
<li value="14">14</li>
<li value="15">15</li>
<li value="16">16</li>
<li value="17">17</li>
<li value="18">18</li>
<li value="19">19</li>
<li value="20">20</li>

</ul>

</div>

CSS:

li {float:left; padding:10px; cursor: pointer;}
    div#scroller {width:300px; height:70px; overflow-x: scroll;}
    ul#ulscroller {list-style: none outside none; margin: 0;
        padding: 0; width:655px;}
    ul#ulscroller li.selected {border:1px solid #000;}

Fiddle: http://jsfiddle.net/7uCS8/

  • 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-18T07:03:09+00:00Added an answer on June 18, 2026 at 7:03 am

    Basic idea:

    var scroller = document.getElementById("scroller"),
        lis = scroller.getElementsByTagName("li"),
        divisionsWidth = lis[0].offsetWidth - 2,
        current = 0,
    scroller.onscroll = function(){
        var selected = Math.floor(scroller.scrollLeft/divisionsWidth);
        if (current!==selected) {
            lis[current].className="";
            lis[selected].className="selected";
            current = selected;
        }
    };
    

    It can be tweaked to change the selection, but it should be a good starting point.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want know if it's possible create a custom delegate in the AppDelegate class,
i want know if is possible, to get a specific element value of a
Want to know ways to store OBJECTS of a Class in some persistent storage.
i want know if it's possible detect and delete a date in string format
I want know if its possible to make a loop purely in CSS (obviously
I want know how I can add an extra column to a Join based
Possible Duplicate: Sort multidimensional array by multiple keys I want know how I can
I want know is it possible to create akka actor in eclipse java projects
i want know how i can manage multiple twitter account on iOS in my
please help me. I want know about what types of flags to run an

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.