hi i have following code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
.card {
border:1px solid transparent;
cursor:pointer;
float:left;
height:136px;
margin:10px;
padding:3px;
width:136px;
}
.ui-corner-all {
-moz-border-radius:4px 4px 4px 4px !important;
}
</style>
</head>
<body>
<!-- <div id="popupContact" style="position:absolute;left:100px;top:100px;width:100px;height:50px;background-color:orange;border:1px solid red ;">
</div> -->
<div class="card ui-corner-all" id="card-208">
<div class="card-name"> Rahul1's Gib 1 </div>
</div>
</body>
</html>
<script type='text/javascript'>
$(document).ready(function(){
var popup_pos=$('#card-208').offset();
var timer;
$("#card-208").mouseenter(function() {
if($("#开发者_C百科divtoshow").length==0){
$("#card-208").append('<div id="divtoshow" style="display:block;background-color:green; border:1px solid black;width:200px;height:100px;position:absolute;">'+
'dsfdssd <a href="#">rahul</a>'+
'</div>')
}
$("#divtoshow").css('position',"absolute");
$("#divtoshow").css('top',popup_pos.top-120);
$("#divtoshow").css('left',popup_pos.left-120);
//~ $("#divtoshow").show();
});
$("#divtoshow").live('mouseleave', function() {
$(this).remove();
});
});
</script>
Q why on mouseleave the divtoshow is not hiding it hide when i again mouseover it .
regards
rahul
You need some modificiations there:
- change 'mouseover' to 'mouseenter'
- use a
.live()
binding for#divtoshow
- access elements within event handlers via
this
Example: http://www.jsfiddle.net/YjC6y/23/
Either you can remove divtoshow on mouse leave event by
$("#divtoshow").remove();
Or on mouse over event of popupContact div, first check existence of divtoshow, and if not exists then append it i.e.
if($("#divtoshow").length==0){
$("#popupContact").append('<div id="divtoshow" style="display:block;background-color:green; border:1px solid black;width:200px;height:100px;position:absolute;">'+
'dsfdssd <div><a href="#">rahul</a></div>'+
'</div>')
}
// css statements will come here
I have done it by myself , i have seen the solutions of others they are good thanks to them for answering .
精彩评论