将div标签放在所需位置

时间:2010-02-03 18:13:28

标签: jquery css html

所有

在以下代码中

<html>
<head>
 <link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />
 <script type="text/javascript" src="http://jqueryui.com/latest/jquery1.3.2.js">       
</script>

<script src="http://jqueryui.com/latest/ui/effects.core.js"></script>
<script src="http://jqueryui.com/latest/ui/effects.slide.js"></script>
<style type="text/css">
 #show { margin: 0px; width: 100px; height: 80px; background: green; border: 1px solid black; position: relative; }
</style>
<script>
$(document).ready(function(){
$("#details").mouseover(function() {
$("#show").show("slide", {}, 1000);
});
</script>

</head>
<body>
<div id="details">keyword</div>
<div id="show" style="display:none;"></div>
</body>

我必须将show div放在页面中间鼠标悬停在详细信息div上。你能告诉我它是如何完成的......

由于.........................

3 个答案:

答案 0 :(得分:2)

这样的东西?

    $("#details").mouseover(function() {
        var theTop = ($(window).height() / 2) - $('#show').height();
        $("#show").show().css({margin:'0 auto', top:theTop});
    });

答案 1 :(得分:0)

如果您正在谈论灯箱效果,那么有很多jQuery插件可供您处理。一些例子:

http://leandrovieira.com/projects/jquery/lightbox/

http://colorpowered.com/colorbox/

http://jqueryui.com/demos/dialog/

答案 2 :(得分:0)

由于您已经在使用jQuery UI,我认为dialog component将是一种简单的方法来实现它。