Home > Web Front-end > JS Tutorial > JavaScript uses DIV to simulate pop-up windows_form scrolling following_javascript skills

JavaScript uses DIV to simulate pop-up windows_form scrolling following_javascript skills

WBOY
Release: 2016-05-16 19:01:29
Original
1208 people have browsed it


[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
] <script> function getPosition() { var top = document.documentElement.scrollTop; var left = document.documentElement.scrollLeft; var height = document.documentElement.clientHeight; var width = document.documentElement.clientWidth; return {top:top,left:left,height:height,width:width}; } function showPop(){ var width = 300; //弹出框的宽度 var height = 160; //弹出框的高度 var obj = document.getElementById("pop"); obj.style.display = "block"; obj.style.position = "absolute"; obj.style.zindex = "999"; obj.style.width = width + "px"; obj.style.height = height + "px"; var Position = getPosition(); leftadd = (Position.width-width)/2; topadd = (Position.height-height)/2; obj.style.top = (Position.top + topadd) + "px"; obj.style.left = (Position.left + leftadd) + "px"; window.onscroll = function (){ var Position = getPosition(); obj.style.top = (Position.top + topadd) +"px"; obj.style.left = (Position.left + leftadd) +"px"; }; } function hidePop(){ document.getElementById("pop").style.display = "none"; } </script>
Related labels:
div
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template