简体   繁体   English

角度如何根据另一个元素更新元素宽度

[英]Angular How to update a element width according to the another element

On my page, the left side I have a side bar menu with can be hide and show. 在页面的左侧,我有一个侧边栏菜单,可以隐藏和显示。 and on the right side is the main page content, it changes its width according to the status of the sidebar. 右侧是主页的内容,它根据侧边栏的状态更改其宽度。

Now In the main page content I have a div which has been set as position:fixed on the top of the screen. 现在在主页内容中,我有一个div,它已设置为position:fixed在屏幕顶部。 I want this div keep the same width as the main page and get updated each time the main page content width has changed( when side bar hide/show or the window width has been changed) how to make this in angular please? 我希望此div保持与主页相同的宽度,并在每次主页内容宽度发生更改时(当边栏隐藏/显示或窗口宽度已更改时)得到更新,如何使它成角度? Thank you very much. 非常感谢你。

If you are using jquery, You can change the width of one element same as other element using following code: 如果使用的是jquery,则可以使用以下代码更改一个元素的宽度,使其与其他元素相同:

$(document).ready(function() {
  $(".second_elem").css({
    'width': ($(".first_elem").width() + 'px')
  });
});

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

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