Em Sta
Em Sta

Reputation: 1706

How to display a span on hover over a circle?

I made an simple website: screenshot of website

My problem is that I want the gray span#te1 and purple span#tre1 to open when the user hovers on the little circles span#punkt1.

I am looking for a solution with CSS3 or jQuery. Also it would be nice if the process had a little delay.

My html:

<span id="tre1"></span>
<span id="te1"></span>
<span id="punkt1"></span>

My CSS:

#tre1 {
    position: absolute;
    top: 105px;
    left: 61.5%;
    width: 0;
    height: 0;
    border-bottom: 100px solid #CCC;
    border-right: 150px solid transparent;
}

#te1 {
    position: absolute;
    top: 205px;
    left: 61.5%;
    background-color: #939;
    width: 150px;
    height: 150px;
}

#punkt1 {
    position: absolute;
    top: 60px;
    left: 60%;
    width: 30px;
    height: 30px;
    border-radius: 15px;
    background-color: #4ec461;
}

Upvotes: 0

Views: 191

Answers (2)

painotpi
painotpi

Reputation: 6996

You could keep #tre1 and #te1 in a separate span like this,

<span class="punkt1">
    <span id="tre1"></span>
    <span id="te1"></span>
</span>

and then do this

$("#punkt1").hover(function () {
    $(".punkt1").show(600);
}, function () {
    $(".punkt1").hide(600);
})

Test Link

UPDATE:

Yes, you can add a .delay() before you .hide()

Test Link

Upvotes: 1

bipen
bipen

Reputation: 36531

considering you have all the required CSS for the little cricles and grey ,purple image..use hover() ..

 $(function(){
   $('#te1,#tre1').hide();
   $('#punkt1').hover(function(){
      $('#te1,#tre1').show('slow');
   },function(){
      $('#te1,#tre1').hide('slow');
   });
 });

with bit of animation

 $('#te1,#tre1').stop().slideDown('slow'); //<--to show;
  $('#te1,#tre1').stop().slideUp('slow'); //<--to hide;

example fiddle here

however make sure you have single element with a same id.. Id should always be unique.it looks like you have multile element( little circles) with same id..

Upvotes: 2

Related Questions