Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the pop-up window effect with jQuery

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report