jQuery Mobile Popup beforeposition事件
jQuery Mobile是一种建立在jQuery之上的网络技术。它被用来制作可在各种设备上访问的响应式内容,如标签、手机和台式机。
在这篇文章中,我们将使用jQuery Mobile Popup beforeposition事件,该事件在弹出窗口计算它将出现的坐标之前被触发。
语法:
- 用指定的beforeposition回调初始化弹出窗口。
$( ".selector" ).popup({
beforeposition: function( event, ui ) {
// Your code goes here
}
});
- 为popupbeforeposition事件绑定一个事件监听器。
$( ".selector" ).on( "popupbeforeposition", function( event, ui ) {} );
参数:它接受一个持有两个参数的回调函数。
- event。它接受Event类型的值。
- ui。它接受Object类型的值。ui对象可以是空的,但为了与整个库的其他事件保持一致。
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>
例子:这个例子描述了jQuery Mobile Popup beforeposition事件的用途。
<!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 - beforeposition Event</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>
(document).ready(function () {
// Initialize the popup with
// beforeposition callback specified.
( "#popup1" ).popup({
beforeposition: function( event, ui ) {
// open the alert when the event is fired.
alert("beforeposition event triggered");
}
});
});
// A function to open the popup to
// demonstrate the beforeposition event.
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 beforeposition Event</h3>
<p id="target">Popup will open here</p>
<div data-role="popup" id="popup1">
<p>Welcome to GeeksforGeeks</p>
</div>
<button style="width: 450px;" onclick="openPopup()">
Open Popup</button>
<p id="write"></p>
</center>
</div>
</body>
</html>
输出: