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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:03:49+00:00 2026-05-31T00:03:49+00:00

This might be rediculous, asking about such a huge bit of code…but basically I

  • 0

This might be rediculous, asking about such a huge bit of code…but basically I have a whole section that loops through 4 divs of content. that works fine. Then i have a section on if you hover over a div, that section will stay active, or if you click the div it will stay constantly active. that bit works on its own aswell. but when i combine them, i have the problem that the loop will always work even if you are hovering, because the loop never stops.

Now, is there a way to make the hover and click bit also pause the loop section. essentailly i am trying to code my own smaller version of all those sliders you see on the internetz

thanks.

$(window).load(function(){
var clicked = 0;
var i = 1;                    
var j = (i - 1);

function myLoop () {       
setTimeout(function () {
   if (clicked == 0) {
$("#nHstuff4").hide();$("#nHpicture4").hide();
$("#nH4").removeClass("active"); 

$("#nHstuff" + j).hide();$("#nHpicture" + j).hide();     
$("#nH" + j).removeClass("active");

$("#nHstuff" + i).show();$("#nHpicture" + i).show();
$("#nH" + i).addClass("active");

        i++;
        j++;

  if (i < 5) {        
     myLoop();        
  }   
  else if (i == 5) {
      i = 1;
      j = 0;
      myLoop();
  } 
   }else{} } ,3000);
}

myLoop();                     

$("#nH1").click(function() {
    if (clicked == 0) {
        clicked = 1;
        $("#nH1").addClass("active");
    }else if (clicked == 1) {
        $(".nHstuff").hide();
        $(".nH").removeClass("active");
        clicked = 0;
    }
});
    $("#nH2").click(function() {
    if (clicked == 0) {
        clicked = 1;
        $("#nH2").addClass("active");
    }else if (clicked == 1) {
        $(".nHstuff").hide();
        $(".nH").removeClass("active");
        clicked = 0;
    }
});
    $("#nH3").click(function() {
    if (clicked == 0) {
        clicked = 1;
        $("#nH3").addClass("active");
    }else if (clicked == 1) {
        $(".nHstuff").hide();
        $(".nH").removeClass("active");
        clicked = 0;
    }
});
    $("#nH4").click(function() {
    if (clicked == 0) {
        clicked = 1;
        $("#nH4").addClass("active");
    }else if (clicked == 1) {
        $(".nHstuff").hide();
        $(".nH").removeClass("active");
        clicked = 0;
    }
});

$("#nH1").hover(function() {if (clicked == 0) {
    $("#nH1stuff").show();$("#nH1picture").show();
}else{}},function(){
    if (clicked == 0) {
    $("#nH1stuff").hide();$("#nH1picture").hide();
    }
    else {}
});

$("#nH2").hover(function() {if (clicked == 0) {
    $("#nH2stuff").show();$("#nH2picture").show();
}else{}},function(){
    if (clicked == 0) {
    $("#nH2stuff").hide();$("#nH2picture").hide();
    }
    else {}
});

$("#nH3").hover(function() {if (clicked == 0) {
    $("#nH3stuff").show();$("#nH3picture").show();
}else{}},function(){
    if (clicked == 0) {
    $("#nH3stuff").hide();$("#nH3picture").hide();
    }
    else {}
}); 

$("#nH4").hover(function() {if (clicked == 0) {
    $("#nH4stuff").show();$("#nH4picture").show();
}else{}},function(){
    if (clicked == 0) {
    $("#nH4stuff").hide();$("#nH4picture").hide();
    }
    else {}
});
});
  • 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-05-31T00:03:50+00:00Added an answer on May 31, 2026 at 12:03 am

    Try this…

    $(window).load(function(){
    var clicked = 0;
    var i = 1;                    
    var j = (i - 1);
    var hovering = false;
    
    function myLoop () {       
    setTimeout(function () {
        if (hovering) return;
       if (clicked == 0) {
    $("#nHstuff4").hide();$("#nHpicture4").hide();
    $("#nH4").removeClass("active"); 
    
    $("#nHstuff" + j).hide();$("#nHpicture" + j).hide();     
    $("#nH" + j).removeClass("active");
    
    $("#nHstuff" + i).show();$("#nHpicture" + i).show();
    $("#nH" + i).addClass("active");
    
            i++;
            j++;
    
      if (i < 5) {        
         myLoop();        
      }   
      else if (i == 5) {
          i = 1;
          j = 0;
          myLoop();
      } 
       }else{} } ,3000);
    }
    
    myLoop();                     
    
    $("#nH1").click(function() {
        if (clicked == 0) {
            clicked = 1;
            $("#nH1").addClass("active");
        }else if (clicked == 1) {
            $(".nHstuff").hide();
            $(".nH").removeClass("active");
            clicked = 0;
        }
    });
        $("#nH2").click(function() {
        if (clicked == 0) {
            clicked = 1;
            $("#nH2").addClass("active");
        }else if (clicked == 1) {
            $(".nHstuff").hide();
            $(".nH").removeClass("active");
            clicked = 0;
        }
    });
        $("#nH3").click(function() {
        if (clicked == 0) {
            clicked = 1;
            $("#nH3").addClass("active");
        }else if (clicked == 1) {
            $(".nHstuff").hide();
            $(".nH").removeClass("active");
            clicked = 0;
        }
    });
        $("#nH4").click(function() {
        if (clicked == 0) {
            clicked = 1;
            $("#nH4").addClass("active");
        }else if (clicked == 1) {
            $(".nHstuff").hide();
            $(".nH").removeClass("active");
            clicked = 0;
        }
    });
    
    $("#nH1").hover(function() {if (clicked == 0) {
        hovering = true;
        $("#nH1stuff").show();$("#nH1picture").show();
    }else{}},function(){
        hovering = false;
        if (clicked == 0) {
        $("#nH1stuff").hide();$("#nH1picture").hide();
        }
        else {}
    });
    
    $("#nH2").hover(function() {if (clicked == 0) {
        hovering = true;
        $("#nH2stuff").show();$("#nH2picture").show();
    }else{}},function(){
        hovering = false;
        if (clicked == 0) {
        $("#nH2stuff").hide();$("#nH2picture").hide();
        }
        else {}
    });
    
    $("#nH3").hover(function() {if (clicked == 0) {
        hovering = true;
        $("#nH3stuff").show();$("#nH3picture").show();
    }else{}},function(){
        hovering = false;
        if (clicked == 0) {
        $("#nH3stuff").hide();$("#nH3picture").hide();
        }
        else {}
    }); 
    
    $("#nH4").hover(function() {if (clicked == 0) {
        hovering = true;
        $("#nH4stuff").show();$("#nH4picture").show();
    }else{}},function(){
        hovering = false;
        if (clicked == 0) {
        $("#nH4stuff").hide();$("#nH4picture").hide();
        }
        else {}
    });
    });
    

    I’ve simply added the variable hovering and I set it to true when hovering and false when not. Then I added a conditional return in the timeout. (It’s similar to what you did with clicked, but using a boolean value rather than an integer).

    There’s a better way to do the timeout. You could use setInterval so you don’t have to keep calling it, and you could then clearInterval when hovering and do another setInterval when you stop hovering. What you have will work though. Just do some googling about setInterval as it’s more appropriate for something like this.

    Incidentally, kudos for making your own version and learning how to do it, rather than just using a plugin 🙂 Plugins are great and usually very handy, but you can’t beat knowing how to do it yourself!

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

Sidebar

Related Questions

This might be a trivial question, but I have not found anything about it,
This might be straight forward but im lost I have this piece of code
this might be a silly question, but well. I have the following code that
This might be a bit on the silly side of things but I need
This might sound like a little bit of a crazy question, but how can
This might be a very basic question, but I'm getting a bit confused. I'm
This might sound like a stupid question, but I am about to pull hear
This might sound stupid, but I'm seriously a newbie at Android programming. I have
This might be a very simple question, but more or less, I'm asking to
This might sound a little stupid but I am still curious about what the

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.