当用户调整 CSS3 定义的可调整大小的文本输入大小时,是否可以捕获 resize 事件?
我使用 CSS 定义了可调整大小的文本输入,如下所示:
#text_input { resize:horizontal; }
<input type="text" id="text_input" />
Is it possible to catch Javascript (preferred in jQuery) event when the user resizes input ?我尝试过使用标准 jQuery .resize() 但它没有像我想象的那样工作。
感谢您的帮助...
I have text input defined to be resizable using CSS, like this:
#text_input { resize:horizontal; }
<input type="text" id="text_input" />
Is it possible to catch Javascript (preferrably in jQuery) event when the user resizes input ? I've tried using standart jQuery .resize() but it doesn't work as I suppose to.
Thanks for any help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 mouseup 事件。正如我尝试的那样,每次调整大小后都会调用它。如果您检查当前大小是否与最后一个大小不同,您的代码甚至不会经常执行。
编辑:
可能是 width() 仍然返回旧值的问题,至少在 chrome 中
you can use the mouseup event. as much as i tried it's called after every resize. if you do a check if the current size is different then the last size your code isn't even executed to often.
EDIT:
might be a problem that width() still returns the old value, at least in chrome
您是否使用过
element.onresize
https://developer.mozilla. org/en/DOM/element.onresize
或使用 jQuery
http://api.jquery.com/调整大小/
Have you used
element.onresize
https://developer.mozilla.org/en/DOM/element.onresize
or using jQuery
http://api.jquery.com/resize/
如果没有 jQuery,它看起来像这样:
编辑1:
使用jQuery,也许这种脚本会起作用:
据我所知,在使用jQuery捕获事件之前,应该调整输入的大小。
EDIT2:
如果您想使用 JS 执行此操作但不使用 jQuery,请尝试这些(浏览器支持可能不同)。
Withou jQuery it will look like this:
<input type="text" id="text_input" onresize="alert('You have changed the size of the window')"/>
EDIT1:
And with jQuery, maybe this kind of script will work:
As I know, the input should be made resizable, before catching the event with jQuery.
EDIT2:
And in case you want to do this with JS but not using jQuery, try these (browser support could be different).