Home  >  Article  >  Web Front-end  >  通过遮罩层实现浮层DIV登录的js代码_javascript技巧

通过遮罩层实现浮层DIV登录的js代码_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:01:201028browse

这个就没什么好说的了。。直接上代码啊!!

首先是HTML的代码。其中包含了登录点击按钮以及一个简陋的登录框。

复制代码 代码如下:






什么都没有用。。。


什么都没有用。。。


什么都没有用。。。


什么都没有用。。。




























































接着是JS脚本代码的实现
复制代码 代码如下:



这里只有显示遮罩层以及登录框的代码。至于隐藏的代码也很简单,就是将遮罩层(shade)的DIV块以及登录框(login)的DIV块的display属性都设置成none应该就没有什么问题了。。

至此,一个简单的通过遮罩层实现浮层DIV登录的功能就实现了。关于美工方面的工作就由大家自行解决了。


在这里,有一个功能求助大家啊。。就是如何让弹出的登录框的DIV块跟随滚动条移动呢??

我的实验代码如下。
复制代码 代码如下:

function loginDivCenter (){
loginDiv.style.top = (document.body.scrollTop + document.body.clientHeight / 2
- loginDivHeight / 2) + "px";
loginDiv.style.left = (document.body.scrollLeft + document.body.clientWidth / 2
- loginDivWidth / 2) + "px";
}

function scall (){
loginDivCenter();
}

window.onscroll=scall;
window.onresize=scall;
window.onload=scall;

但是很不幸的是本人失败了。。网上找了很多,但都不是符合要求的。大多是设置一个setInterval来实现。本人觉得这样做并不理想啊。。。

求各路大神指教啊!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn