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 8683305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:00:25+00:00 2026-06-12T22:00:25+00:00

I have two events: one that is onclick which scrolls to certain div when

  • 0

I have two events: one that is onclick which scrolls to certain div when I click on the menu and the other one in onscroll which "highlight" the menu item when the scroll is near to the div.

My question is: how can I "disallow" the execution of one event while the other is executing.

Here is my code:

function goToByScroll(id){
  var value = $(id).offset().top;
  var scrl = value - 154;
  $('html,body').animate({
    scrollTop: scrl},
  'slow');  
} 

//scroll menu control
$("#menu-home ul li a").click(function(e) {
    e.preventDefault();
    $("#menu-home ul li a").removeClass('menu-home-active');
    $(this).addClass('menu-home-active');
    goToByScroll($(this).attr("href"));    
});

//scroll bar control
$(window).scroll(function() {
  var scrv = $(this).scrollTop();
  var allmenu = $("#menu-home ul li a");
  if(scrv == 0){
    allmenu.removeClass('menu-home-active');
    $('#menu-div1').addClass('menu-home-active');  
  }
  if(scrv > 458 && scrv < 478){
    allmenu.removeClass('menu-home-active');
    $('#menu-div2').addClass('menu-home-active');  
  }
  if(scrv > 989 && scrv < 1009){
    allmenu.removeClass('menu-home-active');
    $('#menu-div3').addClass('menu-home-active');  
  }
  if(scrv >= 1324){
    allmenu.removeClass('menu-home-active');
    $('#menu-div4').addClass('menu-home-active');  
  }
});

Thanks

  • 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-12T22:00:27+00:00Added an answer on June 12, 2026 at 10:00 pm

    First of; the click-event isn’t firing when the scroll-event is (or the other way around). When you get to the scroll event, the click-event is already finished.

    What you should probably do is set a variable on the click event like this:

    function goToByScroll(id) {
        window.isAutoScrolling = true;
        var value = $(id).offset().top;
        var scrl = value - 154;
        $('html,body').animate({scrollTop: scrl}, 'slow', goToByScrollCompleted);
    }
    function goToByScrollCompleted() {
        window.isAutoScrolling = false;
    }
    

    Then you add to the start of the scroll-event this:

    if(window.isAutoScrolling) return;
    

    Also, as for registering the goToByScrollCompleted, this can probably be done in many ways, however, since I don’t know how you do the scrolling I can’t say.

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

Sidebar

Related Questions

I have two click-events, that are nearly similar, but not quite. I am wondering
So I have two click events for button-open and button-close. I have one button
I have an onclick that runs two functions, I want the first one to
I have this script http://jsfiddle.net/gphp/ZMmRv/4/ I have two events: 1 - the div is
I have two tables, events and photos, which relate together via the 'Event_ID' column.
Can we have same delegate for two events ? which have same number of
NOTE: EDITED The real-world situation is a series of events that each have two
I have an .aspx page that contains two buttons one is btnCancel and another
I have a web application that consists of two websites - one running on
I have two screens the one which list the records in a listview ListView

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.