jQuery .resize() 到特定大小
是否可以使用 .resize();
触发某些内容,但仅在调整到特定宽度或高度时才触发?或者只有当尺寸增加时?
Is it possible to trigger something with .resize();
but only when resized to a particular width or height? Or only when size is increased?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您向
resize
添加处理程序,您将能够使用$(this).height()
和$( 从处理程序内部检查元素的大小this).width()
。这样,如果数字不满足某些特征,您可以返回而不需要执行任何操作。通过记住“最后”值并将它们与处理程序中的当前值进行比较,应该可以检测维度增加,例如:
$("#id").resize(function() {
var height = $(this).height();
var 宽度 = $(this).width();
});
但是,请注意: 无法保证在调整元素大小的过程中您的调整大小处理程序将被调用多少次(即您可能会连续触发或仅在最后触发一次),如下所示这取决于浏览器。
If you add a handler to
resize
, you will be able to check the element's size from inside the handler with$(this).height()
and$(this).width()
. This way you can return without doing anything if the numbers do not satisfy certain characteristics.Detecting dimension increase should be possible by remembering the "last" values and comparing them with the current ones from within the handler, for example:
$("#id").resize(function() {
var height = $(this).height();
var width = $(this).width();
});
However, beware: There is no guarantee as to how many times your resize handler will be called during the process of the element being resized (i.e. you may get triggerred continuously or just once at the end), as this depends on the browser.