javascript - 如何将可调整大小的 div 宽度读取到变量中 - Angular 4

标签 javascript jquery html css angular

我正在按照下面的 css 来调整 div 的大小。现在我需要知道用户为 div 选择了多少宽度。

有没有可能做到这一点?

<html>
<head>
<style> 
div {
    border: 2px solid;
    padding: 20px; 
    width: 300px;
    resize: horizontal;
    overflow: auto;
}
</style>
</head>
<body>

<p><b>Note:</b> Internet Explorer does not support the resize property.</p>

<div>Let the user resize both the height and the width of this div element.</div>

</body>
</html>

最佳答案

    $( window ).resize(function() {  // this to get windows width
     console.log( $( window ).width() );
    });

 $('#div-resizable').resize(function() {  // this to get div width
     console.log( $(this).width() );
    });

关于javascript - 如何将可调整大小的 div 宽度读取到变量中 - Angular 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48049843/

相关文章:

javascript - 检查 Cypress 中的控制台消息

javascript - 使用命名空间将原型(prototype)对象分配给对象中的匿名函数,这是未定义的?

javascript - 将 (object.function) 作为参数传递

jquery - 使用 jqBootstrapValidation 插件动态向元素添加验证

jquery - 通过 jquery 在 ASP.NET 中动态从服务器文件系统加载图像

javascript - 限制大数

javascript - 如何有选择地将鼠标事件传递给底层 svg 元素

javascript - 获取自动填充输入的值 - Jquery

html显示格式化文本

javascript - 将鼠标悬停在列表项上,只显示一项而不是全部