Tips for ensuring each page section has a highlighted link

Currently, I am utilizing the one page scroll plugin available at https://github.com/peachananr/onepage-scroll. My website consists of 4 links and 4 sections. What I aim to do is have the link highlighted when on a specific section. For instance, when scrolling to the about section, the about link should be highlighted. Similarly, when reaching the homepage, the homepage link should stand out. Does anyone know how I can achieve this using the aforementioned plugin?

Your assistance would be greatly appreciated.

I want the links to be highlighted similar to the functionality seen on this website: . However, I am uncertain about how to implement this using the plugin mentioned above.

Answer №1

To implement highlighting in your onepage_scroll function, add the following code:

afterMove: function(index) {
  // you can apply javascript to highlight the link here
}

For instance, if your links have css classes "link1" and "link2" and a css class "highlight" for the desired highlighting effect, you can do something similar to this:

afterMove: function(index) {
  if(index === 0){
    $(".link1").toggleClass("highlight")
  }
  if(index === 1){
    $(".link2").toggleClass("highlight")
  }
}

Please note that jQuery is required for this method, and it also automatically removes the highlight when scrolling past each section.

Answer №2

By checking out the documentation, you can see that the plugin being used has support for callbacks. All you need to do is implement it correctly. Below is a sample code demonstrating how to highlight a link using this feature:


$(".main").onepage_scroll({
    afterMove: function(index) {
        if (index === 2) {
            $('#about-link').css({
                "background-color", "yellow"
            });         
        }
    }
});

To see this in action, check out the live demo here: http://jsfiddle.net/preeteshjain/mnL5Lsmz/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What could be causing the image to not show up?

I recently created this HTML code and tested it, expecting an image to be displayed: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Gamedev Canvas Workshop</title> </head> <body> <canvas ...

What is preventing my for loop from reaching the initial index in this visually distinct nested array pattern?

Struggling with rearranging letters in a W shape using arrays. My code seemed to go down instead of reaching level 0. Code snippet: const row = totalLevel =>{ let array = [] for(let i =0;i<totalLevel;i++){ array.push([]) } r ...

Which is the preferred option for constructing and designing forms - using the <table> tag or <div> tags?

Let's consider an example where I want to create a form that looks like this: https://i.sstatic.net/kBLtL.png Now, the question arises - should I use the <table> tag for this job, or is it a better approach to utilize <div> along with CS ...

Error: The module could not be found due to an inability to resolve the parsed request

I am working on a project that uses class components as a requirement by the company, and I cannot switch to function components. After running elint --fix and restarting the project, I encountered an error that is specific to just one file. The error me ...

Utilizing API to Save Images Directly from the Client Side

I am currently in the process of redesigning a website, specifically the Blog section which includes a featured image. I have been researching the best method for saving these images. After following a tutorial that utilized the file.mv() function from ei ...

Website generates dynamic ID for Selenium IDE

Working with Selenium IDE 2.9.1, a plugin for Firefox, I am trying to store the dynamically created ID of a new document and open it at the end. For example: I create a document, and the DataBase automatically assigns the ID: dp_137282 Following this, ...

How to shift a bootstrap-4 button to the right without disrupting the layout

Recently, I delved into learning bootstrap-4 and developed a basic social media website utilizing it. However, I encountered an issue while attempting to align my create-post, login, and register buttons to the right using "float-right" as it caused some f ...

Tips for incorporating material-ui icons into the column component of a data-grid component

I am currently working with the material-ui data-grid and I would like to display Edit icons from material-ui next to each row. Unfortunately, the data-grid does not provide any props specifically for this purpose. Below is the code snippet: import React ...

Conceal flexbox item depending on neighboring element dimensions or content

I've encountered an issue while using a flexbox to display two elements side by side. The left element contains text, while the right one holds a number. When the value in the right element has at least 7 digits ( > 999,999 or < -999,999), I ne ...

Leverage React.JS to iterate through arrays and objects, rendering data seamlessly - even within nested objects

Development of Category's Filter component Implementing the rendering of data from a nested array using React Js Although I attempted to render it as seen below, it is not displaying anything The main focus is on the rendering part only var selecte ...

Encountered an Internal Server Error (500) while attempting to create a new user through localhost:8800/api/auth/register

I'm currently working on setting up a website with registration, login, and logout functionalities using react and mysql. At the moment, I am facing some issues specifically in the registration process. When attempting to create a new user, I encounte ...

Error in Typescript: Cannot assign type 'number' to type 'never'

I encountered an issue related to 'Type 'number' is not assignable to type 'never'.' 'Type 'number' is not assignable to type 'never'.' 'Type 'string' is not assignable t ...

Content positioned beside an image with the help of Bootstrap 4 framework

How can I align text to the right of an image, like a table layout? I experimented with grid layout using <div class="span2"> and <div class="span10"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bo ...

What is the most effective way to bring in "server-side only" code in Next.js?

I am currently working on my index page's getServerSideProps function and I want to utilize a function called foo, which is imported from another local file. This function relies on a specific Node library that cannot be executed in the browser becaus ...

Is it possible to use wildcards in Socket.io rooms or namespaces?

The hierarchy I am working with is as follows: Store -> Manager -> Assistant In this setup, a Manager has access to everything that the Assistant sends, while the Assistant can only access what the Manager explicitly provides. My understanding is t ...

Does SameSite=Lax grant permission for GET requests from third-party sources?

After exploring the MDN documentation on SameSite=Lax, I have come to understand the following: In modern browsers, cookies can be sent along with GET requests initiated by a third-party website or during top-level navigations. This is the default behav ...

Passing Parameter on Angular Material Select Closure Event md-on-close

How can I pass a parameter to a function using Angular Material Select with md-on-close? When I try to log the parameter in my current code, it returns as undefined. This is what I have so far: HTML <md-input-container> <label>Season< ...

Implementing varying font sizes for a mobile device in GWT utilizing CssResource and @if condition

When working with GWT using CssResource and ClientBundle, you can create conditional statements like: @if <deferred-binding-property> <space-separated list of values> { ... css rules ... } In a recent project of mine, I wanted to adjust the ...

Tips for applying multiple colors to text within an option tag

I am currently struggling with adding a drop-down list to my form that displays 2 values, with the second value having a different text color (light gray). After some research, it seems like I need to use JavaScript for this customization. However, as I am ...

Repeated IDs in Angular input components

I'm currently working on developing a toggle button component. The appearance needs to be based on the input label, requiring me to utilize both the `id` and `for` attributes. My concern is what will happen if I include multiple instances of this com ...