我正在使用react-twitter-widgets在我的应用程序上嵌入一个Twitter时间轴。目前,所有内容都可以正确呈现,但是,时间轴高度会延伸整个页面。如何获取窗口小部件高度以便仅占用可用的视图高度?
主仪表板的基础DOM结构是:
<div className="col-md-9 ml-sm-auto col-lg-10 pt-2 px-3">
<div className="row">
<div className="col">
<TitleBar title={this.props.ticker} status={this.props.status}/>
</div>
</div>
<div className="row">
<div className="col-lg-8">
<div className="row">
<div className="col-lg-12 mb-2">
<div className="card border-0">
<div className="card-body">
<Chart chart={this.props.predictionChart} />
</div>
</div>
</div>
<div className="col-lg-6">
<div className="card border-0">
<div className="card-body">
<Chart chart={this.props.errorChart}/>
</div>
</div>
</div>
<div className="col-lg-6">
<div className="card border-0">
<div className="card-body">
<Chart chart={this.props.volumeChart} />
</div>
</div>
</div>
</div>
</div>
<div className="col-lg-4">
<TwitterCard href={this.props.twitter} ticker={this.props.ticker}/>
</div>
</div>
</div>
TwitterCard采用以下格式:
import React from "react";
import { Timeline } from 'react-twitter-widgets';
export class TwitterCard extends React.Component{
constructor(props){
super();
this.state = {
ticker: props.ticker,
href: props.href
}
}
render() {
return (
<Timeline dataSource={{sourceType: 'URL', url: this.props.href}}/>
)
}
}
主要/唯一的css文件如下:
body {
font-size: .875rem;
background-color: #f7f7f7;
}
/*
* Title bar
*/
.title-bar {
padding-right: 15px;
}
/*
* Connection status
*/
#connection-status {
height: 20px;
width: 20px;
border-radius: 50%;
-webkit-border-radius: 50%;
display: block;
}
#connection-status.connected {
background-color: green;
}
#connection-status.disconnected {
background-color: red;
}
/*
* Sidebar
*/
.sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
z-index: 100; /* Behind the navbar */
padding: 0;
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}
.sidebar-sticky {
position: sticky;
top: 48px; /* Height of navbar */
height: calc(100vh - 48px);
padding-top: .5rem;
overflow-x: hidden;
}
.sidebar .nav-link {
font-weight: 500;
color: #333;
}
.sidebar .nav-link{
margin-right: 4px;
color: #999;
}
.sidebar .nav-link.active {
color: #007bff;
}
.sidebar .nav-link:hover,
.sidebar .nav-link.active{
color: inherit;
}
.sidebar-heading {
font-size: .75rem;
text-transform: uppercase;
}
/*
* Navbar
*/
.navbar-brand {
padding-top: .75rem;
padding-bottom: .75rem;
font-size: 1rem;
background-color: rgba(0, 0, 0, .25);
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
}
.navbar .form-control {
padding: .75rem 1rem;
border-width: 0;
border-radius: 0;
}
.form-control-dark {
color: #fff;
background-color: rgba(255, 255, 255, .1);
border-color: rgba(255, 255, 255, .1);
}
.form-control-dark:focus {
border-color: transparent;
box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}
.full-screen{
height: 100vh !important;
}
/*
* Utilities
*/
.border-top { border-top: 1px solid #e5e5e5; }
.border-bottom { border-bottom: 1px solid #e5e5e5; }
答案 0 :(得分:1)
请指定用于呈现窗口小部件的JavaScript。如果它与下面相同,您可以调整属性中的高度。
ReactDOM.render((
<Timeline
dataSource={{
sourceType: 'profile',
screenName: 'twitterdev'
}}
options={{
username: 'TwitterDev',
height: '400'
}}
onLoad={() => console.log('Timeline is loaded!')}
/>