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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:53:27+00:00 2026-06-01T15:53:27+00:00

I want to achieve an effect where a close button appears after some time

  • 0

I want to achieve an effect where a close button appears after some time of hovering the mouse on a div. How could I do that? by the way, I’m so new to jQuery.

Here is an example of something similar to what I want

enter image description here

That “x” in the corner I want to appear in one of my designs.

Thanks to everyone

What I have done so far:

jQuery:

$("#slider #content").on("hover", '.element', function(evt) {
    var top, left;
    top = $(this).offset().top;
    left = $(this).offset().left;
    $(".close-button").css({"top":top, "left":left});
    $(".close-button").show();
 });

The div and the styling of the div I guess is irrelevant if not, I would post it here.

  • 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-01T15:53:28+00:00Added an answer on June 1, 2026 at 3:53 pm

    Here’s one way of doing this, given the following HTML:

    <a href="#" class="modalShow">show modal</a> <a href="#" class="modalShow">show modal</a>
    <div class="modal">
        <span class="close">X</span>
        <p>Some text in the first modal div</p>
    </div>
    <div class="modal">
        <span class="close">X</span>
        <p>Some text in the second modal div</p>
    </div>​
    

    And the CSS:

    .modal {
        display: none;
        width: 50%;
        padding: 0.5em;
        min-height: 6em;
        border: 10px solid #000;
        border: 10px solid rgba(0,0,0,0.5);
        position: absolute;
        top: 20%;
        left: 50%;
        margin-left: -25%;
    }
    span.close {
        display: none;
        position: absolute;
        top: -2.5em;
        left: -2.5em;
        width: 2em;
        height: 2em;
        text-align: center;
        line-height: 2em;
        border: 10px solid #000;
        border: 10px solid rgba(0,0,0,0.5);
        border-radius: 2em;
        background-color: #fff;
        cursor: pointer;
    }​
    

    And the jQuery:

    $('a.modalShow').click(
        function() {
            // finds which link was clicked, and therefore which modal to show
            var i = $(this).index('.modalShow'); 
            // fades all the modal elements out
            $('.modal').fadeOut(1000);
            // fades the relevant modal in
            $('.modal').eq(i).fadeIn(1000);
        });
    
    $('.modal').hover(
        function() {
            // while hovering over the modal, it fades the close element in after a delay
            $(this).find('.close').delay(1000).fadeIn(500);
        },
        function() {
            // after leaving/mouseout of the the modal, has a delay and then fades the close out
            $(this).find('.close').delay(1000).fadeOut(500);
        });
    
    $('span.close').click(
        function(){
            // clicking the close span causes the closest ancestor modal to fadeout
            $(this).closest('.modal').fadeOut(1000);
        });​
    

    JS Fiddle demo.

    References:

    • click().
    • closest().
    • eq().
    • fadeIn().
    • fadeOut().
    • fadeToggle().
    • find().
    • index().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to achieve an effect on a certain div with scriptaculous that does
I want to achieve this effect - that when the parent div is toggled/slides
I want to achieve the effect of a 2D image I have but a
I want to achieve the functionality that this editor has got with its preview
I want to achieve a blur effect using QML. I found references about the
I'm trying to achieve the following effect: +----------------------+-----------------------------------+-----------------------+ | span (absolute left) | div
I want to achieve the same effect as in Visual studio- when you open
I'm new to game programming..What I want to achieve is an effect like bubbles
I want to achieve the effect of following query in Hibernate, but I'm unable
I want to achieve an effect similar to this: Position element fixed vertically, absolute

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.