how to toggle the same object for different object?

Bhavik Joshi

actually I really dont know how to express my problem.

you can see my fiddle so you will come to know about problem.

as you can see in fiddle when I am clicking on the first image the pop up appears but when I am clicking on the other image the popup hides ..I know it is the togggling effect but what to to if I want when I click on second image so the first toggle should over than other should start?

My Code

    <div id='player-back'>
    <img src='http://s6.postimg.org/su0e7812l/player1.png' data-playerid="1" id='p1'/>
    <img src='http://s6.postimg.org/afpv38orx/player2.png' data-playerid="2" id='p2'/>
    <img src='http://s6.postimg.org/h7ga63drh/player3.png' data-playerid="3" id='p3'/>
    <div id='player-popup' style="display:none">
            <span>Player1</span>
    </div>
    </div>

$("img").click(function(){
    var top = $(this).offset().top + $(this).width() + 2;
    var left = $(this).offset().left - $(this).height() / 2;  
    $("#player-popup span").text("Player "+$(this).data("playerid")); 
    $("#player-popup").css({ top: top, left: left }).toggle('slow');

});


#player-back{
    height:250px; 
    background:#0F0;
}
#p1{
    margin-top:50px;
    margin-left:80px;
}
#p2{
    margin-left:150px;
}
#p3{
    margin-left:200px;
}
#player-popup{
    background:orange;
    height:27px;
    width:85px;
    border-radius:10px;
    text-align:center;
    position:absolute;
}
Sami

JSFiddle Demo

You need to hide your popup before toggle in case when you are clicking other object after one. So you can store previously clicked object in a variable like

var prevObj = null;
$("img").click(function(){    
    var top = $(this).offset().top + $(this).width() + 2;
    var left = $(this).offset().left - $(this).height() / 2;  
    $("#player-popup span").text("Player "+$(this).data("playerid")); 

    if(prevObj != this)
        $("#player-popup").hide();
    $("#player-popup").css({ top: top, left: left }).toggle('slow');    
    prevObj = this;
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to toggle the same object for different object?

From Dev

How to search the same object with different Equal concepts?

From Dev

How to generate same object with different values into an ArrayList?

From Dev

How to determine if an object is the same one or different

From Dev

Same object in different classes?

From Dev

Different types of the same object

From Dev

Design pattern - different object in, same object returned

From Dev

Same object in one case, different object in another?

From Dev

Storing same object in different arrays

From Dev

Reference same object with different tags

From Dev

Same object property with different values

From Dev

Using same object in different packages

From Dev

How can I declare same object name for different class?

From Dev

How Tomcat Classloader separates different Webapps object scope in same JVM?

From Dev

How can the same socket object serve different clients?

From Dev

Android how to access the same object through different activities

From Dev

How to use same object with its value in different class

From Dev

How to avoid javax.persistence.EntityExistsException: different object with the same identifier?

From Dev

REST Api returning different object names for the same object, how to handle with RestSharp?

From Java

How to assign values of object type attributes to different object type with same attribute properties in plsql?

From Dev

How to parametrize object by the same type as the given object?

From Dev

How to create an object using same type of object

From Dev

How to access an object value within the same object

From Dev

How to deserialize object to new object with the same name?

From Dev

How to Use the same object among 3 different osgi bundles that is 3 different java plugin projects

From Dev

How to Use the same object among 3 different osgi bundles that is 3 different java plugin projects

From Dev

Java synchronize block on same object in different methods

From Dev

same GooglePlus client object in different activities android

From Dev

Get different JSON representations of the same object

Related Related

  1. 1

    how to toggle the same object for different object?

  2. 2

    How to search the same object with different Equal concepts?

  3. 3

    How to generate same object with different values into an ArrayList?

  4. 4

    How to determine if an object is the same one or different

  5. 5

    Same object in different classes?

  6. 6

    Different types of the same object

  7. 7

    Design pattern - different object in, same object returned

  8. 8

    Same object in one case, different object in another?

  9. 9

    Storing same object in different arrays

  10. 10

    Reference same object with different tags

  11. 11

    Same object property with different values

  12. 12

    Using same object in different packages

  13. 13

    How can I declare same object name for different class?

  14. 14

    How Tomcat Classloader separates different Webapps object scope in same JVM?

  15. 15

    How can the same socket object serve different clients?

  16. 16

    Android how to access the same object through different activities

  17. 17

    How to use same object with its value in different class

  18. 18

    How to avoid javax.persistence.EntityExistsException: different object with the same identifier?

  19. 19

    REST Api returning different object names for the same object, how to handle with RestSharp?

  20. 20

    How to assign values of object type attributes to different object type with same attribute properties in plsql?

  21. 21

    How to parametrize object by the same type as the given object?

  22. 22

    How to create an object using same type of object

  23. 23

    How to access an object value within the same object

  24. 24

    How to deserialize object to new object with the same name?

  25. 25

    How to Use the same object among 3 different osgi bundles that is 3 different java plugin projects

  26. 26

    How to Use the same object among 3 different osgi bundles that is 3 different java plugin projects

  27. 27

    Java synchronize block on same object in different methods

  28. 28

    same GooglePlus client object in different activities android

  29. 29

    Get different JSON representations of the same object

HotTag

Archive