Html 当有人进入我的主页时,如何使图像自动弹出?
我想一个图像自动弹出时,有人去我们的主页。一个他们可以点击关闭后,他们看到它。有人能告诉我如何做到这一点,不需要大量的编码。谢谢你 我会用jQuery来做这件事(我打赌你也在用jQuery做模板:) 请确保您正在页面中调用jQuery库,我建议您将它放在Html 当有人进入我的主页时,如何使图像自动弹出?,html,popup,popupwindow,Html,Popup,Popupwindow,我想一个图像自动弹出时,有人去我们的主页。一个他们可以点击关闭后,他们看到它。有人能告诉我如何做到这一点,不需要大量的编码。谢谢你 我会用jQuery来做这件事(我打赌你也在用jQuery做模板:) 请确保您正在页面中调用jQuery库,我建议您将它放在标记的前面和所有脚本的下面 比如说 <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title&
标记的前面和所有脚本的下面
比如说
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<!-- let's call the following div as the POPUP FRAME -->
<div id="popup">
<!-- and here comes the image -->
<img src="http://i.imgur.com/cVJrCHU.jpg" alt="popup">
<!-- Now this is the button which closes the popup-->
<button id="close">Close button</button>
<!-- and finally we close the POPUP FRAME-->
<!-- everything on it will show up within the popup so you can add more things not just an image -->
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
//your jquery script here
</script>
</body>
</html>
脚本的行为如下:加载页面时,显示
中的内容,如果单击带有id=“close”
的按钮,则弹出窗口将隐藏。在此
中添加您想要的内容,它将显示在弹出窗口中
CSS:非常重要!
您可以在这个实时示例中看到它与HTML一起工作:
我想我做错了什么。你能给我举个例子,说明图像的代码是什么样子的吗?我想我不明白你所说的“当页面加载时,里面的内容会显示出来,如果单击id=“close”按钮,那么弹出窗口就会隐藏。”@user3376481我解释说这看起来非常简单!请再看一看,我已经给了你一个工作的例子,但我还是重新编辑了它!我在代码中添加了很多注释,HTML/JS/CSS,这样您就可以理解和实现它了。明白了吗我很抱歉恢复一个死板的帖子,但是有没有办法让这个弹出窗口在有人点击页面上的超链接后出现,而不是在页面加载后自动出现?D/w我总是愿意提供帮助。为此,您必须绑定(单击)事件上的
,但首先将id属性放入锚定标记。然后写$(“#lingID”)。在(“单击”上,函数(e){e.preventDefault();/*并将用于选择弹出窗口并将其关闭的行置于此处*/)在corse的code>中,整个代码都放在$(document).ready()
中,它包装了另外两行$(“#弹出”)..
和$(“#关闭”)..
行@Blaine@Blaine比较两个javascript代码,一个来自示例,另一个来自我在这里评论的新代码:这非常简单。您应该先学习jQuery,这样对您来说就更容易了
//with this first line we're saying: "when the page loads (document is ready) run the following script"
$(document).ready(function () {
//select the POPUP FRAME and show it
$("#popup").hide().fadeIn(1000);
//close the POPUP if the button with id="close" is clicked
$("#close").on("click", function (e) {
e.preventDefault();
$("#popup").fadeOut(1000);
});
});
/*we need to style the popup with CSS so it is placed as a common popup does*/
#popup {
display:none;
position:absolute;
margin:0 auto;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 9999;
}