简体   繁体   English

使用angularjs根据标题的高度更改顶部填充

[英]change top padding based on height of header using angularjs

i have a fixed header and a mid section following it. 我有一个固定的标题,并在其后有一个中间部分。 When page is resized or opened on smaller screens header height increases and thus expands over the mid section. 在较小的屏幕上调整页面大小或打开页面时,标题高度会增加,从而在中间部分扩展。 I want to dynamically set the value of padding-top in angularjs way. 我想以angularjs方式动态设置padding-top的值。 I know how to do this in jquery but this doesn't looks appropriate to me. 我知道如何在jquery中执行此操作,但这对我来说似乎不合适。

Html : HTML:

<div id="mainPage">
    <div id="header" ng-controller="DecorpotCtrl">

    </div>
    <!-- End of div = header-->

    <div ui-view class="mid"></div>

</div>

css : css:

#header {
  height: auto;
  z-index: 20;
  background-color: white;
  position: fixed;
  width: 100%;
}

.mid {
  height: 84%;
  background-color: white;
  padding-top: 5%;
}

Or there is any other pure css way of doing it. 或者还有其他任何纯CSS方式。

Generally I'd say the angular way, or more precisely "a" angular way, is to make a custom directive and do everything in there, using jQuery or whatever you want :) 通常,我想说的是角度方式,或更确切地说是“ a”角度方式,是使用jQuery或您想要的任何方法来创建自定义指令并在其中执行所有操作:)

Just remember to unhook any custom stuff in the $destroy event of the scope! 只要记住要在作用域的$ destroy事件中解开任何自定义内容!

link: function (scope, element, attrs) {
    function onResize() {

    };
    window.addEventListener("resize", onResize);

    scope.$on("$destroy", function () {
        window.removeEventListener("resize", onResize);
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM