jquery show函数,在一段时间内淡出弹出窗口

时间:2010-06-23 16:49:45

标签: jquery

我使用jquery show函数创建的jquery弹出窗口在几秒钟内消失,这是不打算的。 我希望弹出窗口保持...

我如何告诉jquery这样做?

继承人是我的代码,

jQuery(document).ready(function(){
jQuery('#popuup_div.popup_msg').hide();
$(a.xyz).click(function(e)
{
  var height = jQuery('#popuup_div').height();
  var width = jQuery('#popuup_div').width();
  leftVal=e.pageX-(width/1.5)+"px";
  topVal=e.pageY-(height/13)+"px";

  jQuery('#popuup_div').css({left:leftVal,top:topVal}).show();
});

jQuery('#image').click(function(e)
{
jQuery('#popuup_div').fadeOut('fast');
});
});

html

<div id='popuup_div' class='popup_msg'>
<div id='image'>
 gets the image 
</div>
 <br>
some message
 </div>

css:

.popup_msg{
position:absolute;
z-index:100;
width:700px;
height:250px;
text-align:justify;
color:Black;
font: 14px Verdana, Arial, Helvetica, sans-serif;
background-color:yellow;
}

3 个答案:

答案 0 :(得分:2)

此代码:

jQuery('#image').click(function(e)
{
    jQuery('#popuup_div').fadeOut('fast');
});

是淡化div的代码。根据您提供的代码,弹出div不会消失,除非您单击图像div。即使你没有点击任何东西,你确定div总是会消失吗?您发布的代码中没有任何其他内容会导致弹出窗口淡出。

答案 1 :(得分:1)

您使用什么插件/功能来创建弹出窗口?在整个JavaScript代码中搜索setTimeout,然后粘贴代码段

(使用firefox的Web Developer插件,然后在完成页面加载后,在Web Developer工具栏上转到信息&gt;查看JavaScript,并在那里搜索“setTimeout”。)

答案 2 :(得分:0)

如果您正在为jQuery的库使用第三方插件,那么最好不要这样做。 “淡入”元素的最简单方法是使用jQuery的原生$.fadeIn();

以下是一个例子:

$("#myDiv").fadeIn(1000);

或jQuery的$ .show();

的示例
$("#myDiv").show(1000);

在这两种情况下,您设置的div(其样式应为"display:none;")将在1000毫秒内显示。使用其中任何一个都不应该在任何时间后“淡出”或隐藏元素(因为你没有编写任何代码来执行此操作)。

如果您有任何问题,请询问:)