如何获取对象或嵌入代码的高度,使其适合页面,并且不应该滚动。
class DatabaseManager {
struct DatabaseManagerPtr {
DatabaseManager* ptr;
sqdb::Db * operator->() {
return ptr?ptr->db:nullptr;
}
};
friend struct DatabaseManagerPtr;
private:
static DatabaseManager * sharedInstance_;
sqdb::Db *db = nullptr;
public:
static DatabaseManagerPtr instance() {
return {sharedInstance_};
}
};
var offsetHeight = document.getElementById('myDiv').offsetHeight;
var clientHeight = document.getElementById('myDiv').clientHeight;
alert(clientHeight)
答案 0 :(得分:0)
您需要将min-height
替换为max-height
。使用CSS删除任何默认样式也没什么坏处。
var offsetHeight = document.getElementById('myDiv').offsetHeight;
var clientHeight = document.getElementById('myDiv').clientHeight;
alert(clientHeight)
* {
padding: 0;
margin: 0;
}
<object id="myDiv" data="http://datatables.socialmediahome.com" width="100%" style="max-height:100vh">
</object>
HTML
<object id="myDiv" data="http://datatables.socialmediahome.com" width="100%" style="max-height:100vh">
</object>
CSS
* {
padding: 0;
margin: 0;
overflow: hidden;
}
的Javascript
var offsetHeight = document.getElementById('myDiv').offsetHeight;
var clientHeight = document.getElementById('myDiv').clientHeight;
alert(clientHeight)