Jquery 如何使广告出现在页面中央?

Jquery 如何使广告出现在页面中央?,jquery,css,ads,Jquery,Css,Ads,我想知道如何使广告出现在这个网站上: 不要点击X,否则广告会关闭,第二天才会再次出现。Css: #ad{ position: absolute; /* Or position:fixed; */ z-index: 2; } jQuery: $(document).ready(function(){ $("#ad").css("top", (($(window).height() - $("#popup").outerHeight() ) / 2) + 'px'); $("#ad

我想知道如何使广告出现在这个网站上: 不要点击X,否则广告会关闭,第二天才会再次出现。

Css:

#ad{
position: absolute; /* Or position:fixed; */
z-index: 2;
}
jQuery:

$(document).ready(function(){
    $("#ad").css("top", (($(window).height() - $("#popup").outerHeight() ) / 2) + 'px');
    $("#ad").css("left",(($(window).width() - $("#popup").outerWidth() )/ 2 ) + 'px');
});
$("#blanket").css("height", $(document).height() + 'px');
请注意,如果您想使用图像,您需要将其写成:

$("#ad").css("top", (($(window).height() - $("#popup").outerHeight() - imgheight) / 2) + 'px');
因为基本上,图像是在文档dom加载后加载的,所以我通常将图像高度解析为属性之一,这样我就知道要减去什么

请注意,这个链接对我不起作用,所以我只是根据以前的作品写的

编辑: 要创建用户界面屏幕块

CSS:

jQuery:

$(document).ready(function(){
    $("#ad").css("top", (($(window).height() - $("#popup").outerHeight() ) / 2) + 'px');
    $("#ad").css("left",(($(window).width() - $("#popup").outerWidth() )/ 2 ) + 'px');
});
$("#blanket").css("height", $(document).height() + 'px');
HTML:



Offtopic:我希望您知道这是一个真正不需要的“功能”。如果我在一个网站上看到这一点,我以后会尽量避免访问该网站…@PoweRoy我不知道你是否成功打开了该网站,但它看起来像这样,而且每天只让你烦恼一次,我打开了它,这就是我抱怨的原因;)根据网站内容的不同,您可能一天只想查看一次页面。这意味着每次关闭广告。嗨,对不起,你可以在这里查看屏幕截图,不知道为什么它不适合你:你需要添加某种按钮来关闭它,阅读jquery:hide(),并每天显示一次-你需要使用cookie。。。