官术网_书友最值得收藏!

Preventing body scroll

We have a problem, though. Our modal panel, despite being full screen, is still a child of thebodytag. This means we can stillscrollthe main window! We don't want users to interact with the main window in any way while the modal is open, so we must disable scrolling on thebody.

The trick is to add the CSSoverflowproperty to thebodytag and set it tohidden. This has the effect of clipping any overflow (that is, part of the page not currently in view), and the rest of the content will be made invisible.

We'll need to dynamically add and remove this CSS rule, as we obviously want to be able to scroll through the page when the modal is closed. So, let's create a class calledmodal-openthatwe can apply to thebodytag when the modal is open.

style.css:

body.modal-open {
  overflow: hidden;
position: fixed;
}

We can usev-bind:classto add/remove this class, right? Unfortunately, no. Remember that Vue only has dominion over the element where it is mounted:

<body>
  <p id="app"> 
    <!--This is where Vue has dominion and can modify the page freely-->
  </p>
  <!--Vue is unable to change this part of the page or any ancestors-->
</body>

If we add a directive to thebodytag, it willnotbe seen by Vue.

主站蜘蛛池模板: 阳泉市| 兴和县| 兴海县| 噶尔县| 肇州县| 宜君县| 洛宁县| 新绛县| 淮滨县| 秦皇岛市| 南川市| 江陵县| 黎城县| 海原县| 且末县| 宾川县| 炎陵县| 郯城县| 石林| 岑巩县| 信丰县| 崇信县| 临洮县| 隆德县| 新闻| 赞皇县| 卢湾区| 旅游| 江陵县| 清镇市| 黎平县| 神农架林区| 万荣县| 黄大仙区| 临洮县| 大邑县| 罗甸县| 凤冈县| 明水县| 嘉峪关市| 馆陶县|