Home  >  Article  >  Web Front-end  >  Example analysis of how to simply implement the jQuery pop-up effect

Example analysis of how to simply implement the jQuery pop-up effect

小云云
小云云Original
2017-12-26 14:45:381472browse

This article mainly teaches you how to simply implement the jQuery pop-up effect. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

The example in this article shares the specific code for jQuery pop-up window effect display for your reference. The specific content is as follows


<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>弹窗</title>
  <script type="text/javascript" src="../jquery-3.2.1.min.js"></script>

  <style type="text/css">
   *{margin: 0px;padding: 0px;}
   #login{height:300px;width: 300px;border: 1px solid #ddd;position: absolute; }
   #close{position: absolute;right: 0px;top: 0px;}
  </style>


  <script type="text/javascript">

  // JS创建一个p标签,也就是节点元素
  // window.onload=function(){
  //  document.createElement(&#39;p&#39;);
  // }

  // 使用jQuery创建:$(&#39;<p>&#39;);带尖括号的是创建,不带是选择的意思
  $(function(){
   // var op=$(&#39;<p>&#39;);
   // $(&#39;body&#39;).append(op);

   $(&#39;input&#39;).click(function(){
   var oLogin=$(&#39;<p id="login"><p>用户名<input type="text"></p><p>密码<input type="text"></p><p id="close">X</p></p>&#39;);//此功能就相当于body中注释的代码

   $(&#39;body&#39;).append(oLogin);
   oLogin.css(&#39;left&#39;,($(window).width()-oLogin.outerWidth())/2);
   oLogin.css(&#39;top&#39;,($(window).width()-oLogin.outerHeight())/2);//是弹窗能够出现在浏览器的中间

   $("#close").click(function(){
    oLogin.remove();
   })

   // jquery 中$()里window不用加引号
   // 添加resize()浏览器窗口大小改变
   // scroll():滚动条,以下的作用是当滚动条滚动时候,弹窗的位置也不变化
   $(window).on("resize scroll",function(){
    oLogin.css(&#39;left&#39;,($(window).width()-oLogin.outerWidth())/2+$(window).scrollLeft());
    oLogin.css(&#39;top&#39;,($(window).width()-oLogin.outerHeight())/2+$(window).scrollTop());
   })

   });

  });

  </script>
</head>
<body>
 <input type="button" value="点击">
 <!-- <p id="login">
  <p>用户名<input type="text"></p>
  <p>密码<input type="text"></p>
  <p id="close">X</p>
 </p> -->
</body>
</html>

Points used:

jQuery creation: $('e388a4556c0f65e1904146cc1a846bee');

Pop-up window location:


oLogin.css(&#39;left&#39;,($(window).width()-oLogin.outerWidth())/2);
oLogin.css(&#39;top&#39;,($(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(&#39;left&#39;,($(window).width()-oLogin.outerWidth())/2+$(window).scrollLeft());
oLogin.css(&#39;top&#39;,($(window).width()-oLogin.outerHeight())/2+$(window).scrollTop());
   })

Related recommendations:

The pop-up window in H5 cannot How to solve the problem of pop-up using webview

How to use js in php to pass parameters to the pop-up window

Personalized web page small pop-up window

The above is the detailed content of Example analysis of how to simply implement the jQuery pop-up effect. For more information, please follow other related articles on the PHP Chinese website!

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