jQuery UI可调整的start事件
jQuery UI由GUI部件、视觉效果和主题组成,使用HTML、CSS和jQuery实现。 jQuery UI对于构建网页的UI界面非常有用。当调整大小的操作开始时,jQuery UI Resizable start事件被触发。
语法:
初始化可调整大小的启动事件。
$( ".selector" ).resizable({
start: function( event, ui ) {}
});
- 为resizestart事件绑定一个事件监听器。
$( ".selector" ).on( "resizestart", function( event, ui ) {} );
参数:它接受一个有两个参数的回调函数。
event:它接受事件类型值。
ui:它接受对象类型的值,如下图所示。
- element。当元素要被调整大小时,这个jQuery对象就会被代表。
- helper。这个jQuery对象在帮助器被调整大小时被代表。
- originalElement。这个jQuery对象在原始元素被包裹时被表示。
- originalPosition。这个参数是指在调整可调整大小之前,代表左边和上面的位置。
- originalSize。这个参数是在调整可调整大小之前以宽度和高度表示的大小。
- position。这个参数是当前的位置,表示为左边和上面。
- size。这个参数是当前的尺寸,表示为宽度和高度。
CDN链接:首先,添加你的项目需要的jQuery UI脚本。
<link rel=”stylesheet” href=”//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css”>
<script src=”//code.jquery.com/jquery-1.12.4.js”></script>
<script src=”//code.jquery.com/ui/1.12.1/jquery-ui.js”></script>
例子:这个例子演示了jQuery UI可调整的start事件。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href=
"//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src=
"//code.jquery.com/jquery-1.12.4.js">
</script>
<script src=
"//code.jquery.com/ui/1.12.1/jquery-ui.js">
</script>
<style>
h1 {
color: green;
}
#GFG {
width: 150px;
height: 150px;
background: green;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
</style>
</head>
<body>
<center>
<h1 style="color:green;">
GeeksforGeeks
</h1>
<h3>jQuery UI Resizable start Events</h3>
<div id="log"></div>
<div id="GFG">GeeksforGeeks</div>
</center>
<script>
(document).ready(function () {
("#GFG").resizable({
start: function (event, ui) { }
});
("#GFG").on("resizestart", function (event, ui) {
("#log").html('Resize operation has been started.');
});
});
</script>
</body>
</html>
输出:
jQuery UI可调整的启动事件