How to change class on scroll to current icon in vertical menu (onepage website)?












0















I have vertical menu (Divi theme - Wordpress). I to make an icon red (has class active2) when you are on section that belongs to that icon - menu item.



That works fine on click but I want that class goes to another icon that belongs to current section on scroll.






jQuery(document).ready(function($) {
$(".fa-bars").addClass('active2');
$(".fas").click(function() {
$('.fas').not(this).removeClass('active2');
$(this).addClass('active2');
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="top-menu" class="nav">
<li id="menu-item-36" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-36"><a href="#section01"><i id="ikonabars" class="fas fa-bars active2"></i></a></li>
<li id="menu-item-30" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-30"><a href="#section02"><i id="ikonadom" class="fas fa-home"></i></a></li>
<li id="menu-item-38" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-38"><a href="#section03"><i id="ikonatools" class="fas fa-wrench"></i></a></li>
<li id="menu-item-40" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-40"><a href="#section04"><i id="ikonabook1" class="fas fa-book"></i></a></li>
<li id="menu-item-41" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-41"><a href="#section05"><i id="ikonainbox" class="fas fa-inbox"></i></a></li>
<li id="menu-item-42" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-42"><a href="#section06"><i id="ikonausers" class="fas fa-users"></i></a></li>
<li id="menu-item-43" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-43"><a href="#section07"><i id="ikonauserplus" class="fas fa-user-plus"></i></a></li>
<li id="menu-item-39" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-39"><a href="#section08"><i id="ikonabook2" class="fas fa-book-open"></i></a></li>
</ul>





(I want that icon turn to red on scroll also - not click - when you scroll to #section03 should 3. icon get class active2 and turn to red)










share|improve this question

























  • So did you want the colour of the icon you have just clicked to turn red? And then also remove the red colour from the other icons?

    – Christheoreo
    Nov 23 '18 at 9:24











  • That allready works fine. I want that icon turn to red on scroll also - not click - when you scroll to #section03 should 3. icon get class active2 and turn to red

    – Petra
    Nov 23 '18 at 9:47











  • Check Add class when page scroll reach at specific id

    – Mohammad
    Nov 24 '18 at 7:30
















0















I have vertical menu (Divi theme - Wordpress). I to make an icon red (has class active2) when you are on section that belongs to that icon - menu item.



That works fine on click but I want that class goes to another icon that belongs to current section on scroll.






jQuery(document).ready(function($) {
$(".fa-bars").addClass('active2');
$(".fas").click(function() {
$('.fas').not(this).removeClass('active2');
$(this).addClass('active2');
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="top-menu" class="nav">
<li id="menu-item-36" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-36"><a href="#section01"><i id="ikonabars" class="fas fa-bars active2"></i></a></li>
<li id="menu-item-30" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-30"><a href="#section02"><i id="ikonadom" class="fas fa-home"></i></a></li>
<li id="menu-item-38" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-38"><a href="#section03"><i id="ikonatools" class="fas fa-wrench"></i></a></li>
<li id="menu-item-40" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-40"><a href="#section04"><i id="ikonabook1" class="fas fa-book"></i></a></li>
<li id="menu-item-41" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-41"><a href="#section05"><i id="ikonainbox" class="fas fa-inbox"></i></a></li>
<li id="menu-item-42" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-42"><a href="#section06"><i id="ikonausers" class="fas fa-users"></i></a></li>
<li id="menu-item-43" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-43"><a href="#section07"><i id="ikonauserplus" class="fas fa-user-plus"></i></a></li>
<li id="menu-item-39" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-39"><a href="#section08"><i id="ikonabook2" class="fas fa-book-open"></i></a></li>
</ul>





(I want that icon turn to red on scroll also - not click - when you scroll to #section03 should 3. icon get class active2 and turn to red)










share|improve this question

























  • So did you want the colour of the icon you have just clicked to turn red? And then also remove the red colour from the other icons?

    – Christheoreo
    Nov 23 '18 at 9:24











  • That allready works fine. I want that icon turn to red on scroll also - not click - when you scroll to #section03 should 3. icon get class active2 and turn to red

    – Petra
    Nov 23 '18 at 9:47











  • Check Add class when page scroll reach at specific id

    – Mohammad
    Nov 24 '18 at 7:30














0












0








0


0






I have vertical menu (Divi theme - Wordpress). I to make an icon red (has class active2) when you are on section that belongs to that icon - menu item.



That works fine on click but I want that class goes to another icon that belongs to current section on scroll.






jQuery(document).ready(function($) {
$(".fa-bars").addClass('active2');
$(".fas").click(function() {
$('.fas').not(this).removeClass('active2');
$(this).addClass('active2');
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="top-menu" class="nav">
<li id="menu-item-36" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-36"><a href="#section01"><i id="ikonabars" class="fas fa-bars active2"></i></a></li>
<li id="menu-item-30" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-30"><a href="#section02"><i id="ikonadom" class="fas fa-home"></i></a></li>
<li id="menu-item-38" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-38"><a href="#section03"><i id="ikonatools" class="fas fa-wrench"></i></a></li>
<li id="menu-item-40" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-40"><a href="#section04"><i id="ikonabook1" class="fas fa-book"></i></a></li>
<li id="menu-item-41" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-41"><a href="#section05"><i id="ikonainbox" class="fas fa-inbox"></i></a></li>
<li id="menu-item-42" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-42"><a href="#section06"><i id="ikonausers" class="fas fa-users"></i></a></li>
<li id="menu-item-43" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-43"><a href="#section07"><i id="ikonauserplus" class="fas fa-user-plus"></i></a></li>
<li id="menu-item-39" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-39"><a href="#section08"><i id="ikonabook2" class="fas fa-book-open"></i></a></li>
</ul>





(I want that icon turn to red on scroll also - not click - when you scroll to #section03 should 3. icon get class active2 and turn to red)










share|improve this question
















I have vertical menu (Divi theme - Wordpress). I to make an icon red (has class active2) when you are on section that belongs to that icon - menu item.



That works fine on click but I want that class goes to another icon that belongs to current section on scroll.






jQuery(document).ready(function($) {
$(".fa-bars").addClass('active2');
$(".fas").click(function() {
$('.fas').not(this).removeClass('active2');
$(this).addClass('active2');
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="top-menu" class="nav">
<li id="menu-item-36" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-36"><a href="#section01"><i id="ikonabars" class="fas fa-bars active2"></i></a></li>
<li id="menu-item-30" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-30"><a href="#section02"><i id="ikonadom" class="fas fa-home"></i></a></li>
<li id="menu-item-38" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-38"><a href="#section03"><i id="ikonatools" class="fas fa-wrench"></i></a></li>
<li id="menu-item-40" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-40"><a href="#section04"><i id="ikonabook1" class="fas fa-book"></i></a></li>
<li id="menu-item-41" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-41"><a href="#section05"><i id="ikonainbox" class="fas fa-inbox"></i></a></li>
<li id="menu-item-42" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-42"><a href="#section06"><i id="ikonausers" class="fas fa-users"></i></a></li>
<li id="menu-item-43" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-43"><a href="#section07"><i id="ikonauserplus" class="fas fa-user-plus"></i></a></li>
<li id="menu-item-39" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-39"><a href="#section08"><i id="ikonabook2" class="fas fa-book-open"></i></a></li>
</ul>





(I want that icon turn to red on scroll also - not click - when you scroll to #section03 should 3. icon get class active2 and turn to red)






jQuery(document).ready(function($) {
$(".fa-bars").addClass('active2');
$(".fas").click(function() {
$('.fas').not(this).removeClass('active2');
$(this).addClass('active2');
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="top-menu" class="nav">
<li id="menu-item-36" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-36"><a href="#section01"><i id="ikonabars" class="fas fa-bars active2"></i></a></li>
<li id="menu-item-30" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-30"><a href="#section02"><i id="ikonadom" class="fas fa-home"></i></a></li>
<li id="menu-item-38" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-38"><a href="#section03"><i id="ikonatools" class="fas fa-wrench"></i></a></li>
<li id="menu-item-40" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-40"><a href="#section04"><i id="ikonabook1" class="fas fa-book"></i></a></li>
<li id="menu-item-41" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-41"><a href="#section05"><i id="ikonainbox" class="fas fa-inbox"></i></a></li>
<li id="menu-item-42" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-42"><a href="#section06"><i id="ikonausers" class="fas fa-users"></i></a></li>
<li id="menu-item-43" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-43"><a href="#section07"><i id="ikonauserplus" class="fas fa-user-plus"></i></a></li>
<li id="menu-item-39" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-39"><a href="#section08"><i id="ikonabook2" class="fas fa-book-open"></i></a></li>
</ul>





jQuery(document).ready(function($) {
$(".fa-bars").addClass('active2');
$(".fas").click(function() {
$('.fas').not(this).removeClass('active2');
$(this).addClass('active2');
});
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="top-menu" class="nav">
<li id="menu-item-36" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-36"><a href="#section01"><i id="ikonabars" class="fas fa-bars active2"></i></a></li>
<li id="menu-item-30" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-30"><a href="#section02"><i id="ikonadom" class="fas fa-home"></i></a></li>
<li id="menu-item-38" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-38"><a href="#section03"><i id="ikonatools" class="fas fa-wrench"></i></a></li>
<li id="menu-item-40" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-40"><a href="#section04"><i id="ikonabook1" class="fas fa-book"></i></a></li>
<li id="menu-item-41" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-41"><a href="#section05"><i id="ikonainbox" class="fas fa-inbox"></i></a></li>
<li id="menu-item-42" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-42"><a href="#section06"><i id="ikonausers" class="fas fa-users"></i></a></li>
<li id="menu-item-43" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-43"><a href="#section07"><i id="ikonauserplus" class="fas fa-user-plus"></i></a></li>
<li id="menu-item-39" class="ps2id menu-item menu-item-type-custom menu-item-object-custom menu-item-39"><a href="#section08"><i id="ikonabook2" class="fas fa-book-open"></i></a></li>
</ul>






javascript jquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 9:48







Petra

















asked Nov 23 '18 at 9:20









PetraPetra

114




114













  • So did you want the colour of the icon you have just clicked to turn red? And then also remove the red colour from the other icons?

    – Christheoreo
    Nov 23 '18 at 9:24











  • That allready works fine. I want that icon turn to red on scroll also - not click - when you scroll to #section03 should 3. icon get class active2 and turn to red

    – Petra
    Nov 23 '18 at 9:47











  • Check Add class when page scroll reach at specific id

    – Mohammad
    Nov 24 '18 at 7:30



















  • So did you want the colour of the icon you have just clicked to turn red? And then also remove the red colour from the other icons?

    – Christheoreo
    Nov 23 '18 at 9:24











  • That allready works fine. I want that icon turn to red on scroll also - not click - when you scroll to #section03 should 3. icon get class active2 and turn to red

    – Petra
    Nov 23 '18 at 9:47











  • Check Add class when page scroll reach at specific id

    – Mohammad
    Nov 24 '18 at 7:30

















So did you want the colour of the icon you have just clicked to turn red? And then also remove the red colour from the other icons?

– Christheoreo
Nov 23 '18 at 9:24





So did you want the colour of the icon you have just clicked to turn red? And then also remove the red colour from the other icons?

– Christheoreo
Nov 23 '18 at 9:24













That allready works fine. I want that icon turn to red on scroll also - not click - when you scroll to #section03 should 3. icon get class active2 and turn to red

– Petra
Nov 23 '18 at 9:47





That allready works fine. I want that icon turn to red on scroll also - not click - when you scroll to #section03 should 3. icon get class active2 and turn to red

– Petra
Nov 23 '18 at 9:47













Check Add class when page scroll reach at specific id

– Mohammad
Nov 24 '18 at 7:30





Check Add class when page scroll reach at specific id

– Mohammad
Nov 24 '18 at 7:30












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443742%2fhow-to-change-class-on-scroll-to-current-icon-in-vertical-menu-onepage-website%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443742%2fhow-to-change-class-on-scroll-to-current-icon-in-vertical-menu-onepage-website%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy