How to realize the pop-up window effect with jQuery
This article mainly introduces the relevant knowledge of "how to achieve pop-up window effect in jQuery". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope this article "how to achieve pop-up window effect in jQuery" can help you solve the problem.
The specific code is as follows
Pop-up window * {margin: 0pxscape padding: 0px;} # login {height:300px;width: 300pxbot border: 1px solid # ddd;position: absolute;} # close {position: absolute;right: 0pxash top: 0px;} / JS create a div tag, that is, the node element / / _ window.onload=function () {/ / document.createElement ('div'); / / create using jQuery: $('') Create with angle brackets, without meaning of choice $(function () {/ / var oDiv=$ (''); / / ('body') .append (oDiv); $(' input') .click (function () {var oLogin=$ (')
User name
Password
X'); / / this feature is equivalent to the code commented in body $('body') .append (oLogin); oLogin.css (' left', ($(window). Width ()-oLogin.outerWidth ()) / 2); oLogin.css ('top', ($(window). Width ()-oLogin.outerHeight () / 2); / / the pop-up window can appear in the middle of the browser $("# close") .click (function () {oLogin.remove ()) }) / / window does not need to be quoted in $() in jquery / / add resize () browser window size change / / scroll (): scroll bar, the following function is that when the scroll bar scrolls, the position of the pop-up window does not change $_ (window) .on ("resize scroll", function () {oLogin.css ('left', ($(window). Width ()-oLogin.outerWidth ()) / 2 scroll $(window). ScrollLeft () OLogin.css ('top', ($(window). Width ()-oLogin.outerHeight ()) / 2) $(window). ScrollTop ();});})
Points used:
JQuery creation: $('')
The position of the pop-up window:
OLogin.css ('left', ($(window). Width ()-oLogin.outerWidth ()) / 2); oLogin.css (' top', ($(window). Width ()-oLogin.outerHeight ()) / 2)
When the scroll bar scrolls, the position of the pop-up window changes:
$_ (window) .on ("resize scroll", function () {oLogin.css ('left', ($(window). Width ()-oLogin.outerWidth ()) / 2 million $(window). ScrollLeft ()); oLogin.css (' top', ($(window). Width ()-oLogin.outerHeight ()) / 2 million $(window). ScrollTop ();}) this is the end of the introduction about "how jQuery achieves pop-up window effect". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.