简体   繁体   English

我没有利用Media Query使Angular 2应用程序响应。 我只是在使用javascript。 这是一个好习惯吗?

[英]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.

相关问题 我想让我的页面响应移动,但似乎媒体查询不起作用,为什么? - I am tring to make my page mobile responsive but it seems like media query does not work, why? 我正在尝试用 Javascript 制作一个计算器。 但它以某种方式不起作用 - I am trying to make a calculator in Javascript. But it is not working somehow 我正在努力使我的幻灯片响应 - i am struggling to Make my slideshow responsive 我正在尝试使用JavaScript创建一个计算器。 - I am trying to create a calculator with javascript. 我正在使用这个javascript来“未定义”。 为什么? - I am geting “undefined” with this javascript. Why? 我正在 javascript 中开发 duolingo 类型的句子练习。 我已经实现了它,但它需要更多改进 - I am developing duolingo type sentence practice in javascript. I have implemented it but it needs more improvement 我正在使用javascript计算页面加载时间。 但不幸的是,我得到的是负值。 - I am calculating page load time using javascript. But unfortunately I am getting it in negative value. 的JavaScript。 简单的代码,但无法在wer浏览器中加载。 我才刚开始 - Javascript. simple code but not loading in wer browser. I am just starting 我正在使用 javascript 创建一个待办事项列表。 我想让它在选中/取消选中复选框时添加/删除 class - I am creating a to do list using javascript. I want to make it so that when the check box is check/unchecked it adds/removes a class 我是 JavaScript 的新手。 请帮我进行 javascript 验证 - I am new to JavaScript. please help me for javascript validation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM