[英]I am not utilizing Media Query to make my Angular 2 app responsive. I am just using javascript. Is this a good practice?
I want my app to be fully responsive in any screen size. 我希望我的应用在任何屏幕尺寸下都能完全响应。 I am not utilizing Media Query and I am just using javascript to make my app responsive with Angular 2: [style.width], *ngIf="isEmpty" , etc.. Is this a good practice?
我没有使用Media Query,而是使用javascript使我的应用程序响应于Angular 2: [style.width],* ngIf =“ isEmpty”等。这是一个好习惯吗? Below is a sample of my working code.
以下是我的工作代码示例。 Thanks.
谢谢。
onResize(event: any) {
this.getResponsive();
}
getResponsive(){
var modelQty = this.subCategories.length;
var margin = 10;
var fWidth = (screen.width-40) / 10 - margin;
if(fWidth <= 110)
fWidth = 110;
this.frameWidth = fWidth;
this.frameWidthStr = fWidth + 'px'; //[style.width]="frameWidthStr"
this.frameHeight = fWidth + 20 + 'px';
this.imageSize = fWidth *.75 + 'px'; //[style.height]="imageSize"
var totalWidth = (fWidth + margin)*modelQty;
var tMarginLeft = (window.innerWidth - totalWidth)/2;
if(tMarginLeft > 10){
this.marginLeft = tMarginLeft + 'px';
this.marginRight = '10px';
}
else {
this.marginLeft = 10 + 'px';
var tWidth = fWidth + 10+2;
var delta = (window.innerWidth-15) % tWidth;
let line = window.innerWidth/tWidth;
line = line - delta / tWidth;
this.marginRight = 10 + delta/line + 'px'; //[style.margin-right]="marginRight"
}
}
Rather than try and shoehorn angular into a custom responsive layout why not work with angular and use a compatible layout library to achieve your requirements. 与其尝试将角shoe放到自定义响应式布局中,不如不使用角形并使用兼容的布局库来满足您的要求。
This one is highly recommended 强烈推荐
https://github.com/angular/flex-layout https://github.com/angular/flex-layout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.