最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Svelte: <svelte:window bind:innerHeight > is not working with style attribute in div on window resize

programmeradmin1浏览0评论

On window resize, I have tried to add dynamic height as style property in div element, using svelte special element <svelte:window bind:innerHeight /> but I am not getting the proper result which I am looking for, Is there anything I missed.

Code:-

<script>
    var innerHeight;
</script>

<svelte:window bind:innerHeight={innerHeight} />

<div style="height: {innerHeight};">
    <h1>window height : {innerHeight}</h1>
</div>

Output:-

enter image description here

Thanks in advance

On window resize, I have tried to add dynamic height as style property in div element, using svelte special element <svelte:window bind:innerHeight /> but I am not getting the proper result which I am looking for, Is there anything I missed.

Code:-

<script>
    var innerHeight;
</script>

<svelte:window bind:innerHeight={innerHeight} />

<div style="height: {innerHeight};">
    <h1>window height : {innerHeight}</h1>
</div>

Output:-

enter image description here

Thanks in advance

Share Improve this question asked Jul 24, 2020 at 10:34 Bejoy N.JBejoy N.J 652 silver badges7 bronze badges 1
  • I have got the answer since the innerHeight is unit less value we have to add px like this style="height: {innerHeight}px;" – Bejoy N.J Commented Jul 24, 2020 at 10:54
Add a ment  | 

1 Answer 1

Reset to default 8

innerHeight is a unit less value, in order to use it as you do, you have to add the unit yourself to the style tag'

style="height: {innerHeight}px;"

(note the extra px)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论