jQuery Mobile Popup open()方法
jQuery Mobile是一种网络技术,用于创建响应性和可访问的网站和网络应用。它建立在jQuery的基础上。
在这篇文章中,我们将使用jQuery Mobile Popup open()方法,使用指定的选项打开弹出窗口。
语法:
$( ".selector" ).popup( "open", options );
这里的选项参数是接受4个键的对象类型。
- x:你想显示弹出窗口的X坐标。
- y:你想显示弹出窗口的y坐标。
- transition。它定义了打开弹出窗口时要使用的过渡。它接受一个字符串,默认值是一个空字符串。
- positionTo:一个jQuery选择器可以用来定义弹出窗口显示的位置。
CDN链接:首先,在项目中添加jQuery CDN链接。
<link rel=”stylesheet” href=”https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css” />
<script src=”https://code.jquery.com/jquery-2.1.3.js”></script>
<script src=”https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js”></script>
例子:在下面的例子中,我们使用positionTo选项来定义我们想要打开弹出窗口的位置。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible"
content="IE=edge" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0" />
<title>Popup - reposition method</title>
<link rel="stylesheet"
href=
"https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"/>
<script src=
"https://code.jquery.com/jquery-2.1.3.js">
</script>
<script src=
"https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js">
</script>
<script>
function openPopup(){
$( "#popup1" ).popup( "open",
{positionTo: "#target"} );
}
</script>
</head>
<body>
<div data-role="page">
<center>
<h2 style="color: green">GeeksforGeeks</h2>
<h3>jQuery Mobile Popup open Method</h3>
<p id="target">Popup will open here</p>
<div data-role="popup" id="popup1">
<p>Welcome to GeeksforGeeks</p>
</div>
<button onclick="openPopup()">
Open Popup
</button>
</center>
</div>
</body>
</html>
输出: