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

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.

主站蜘蛛池模板: 无为县| 辰溪县| 铁岭县| 城口县| 田阳县| 宣化县| 开江县| 平湖市| 白河县| 永安市| 循化| 乌鲁木齐县| 澄江县| 明溪县| 汶川县| 沿河| 舞阳县| 清水县| 桦川县| 泰和县| 民勤县| 榆中县| 白水县| 湟源县| 吴忠市| 建水县| 临洮县| 柳河县| 德清县| 闸北区| 本溪市| 深泽县| 和田市| 南雄市| 寿光市| 公主岭市| 迁安市| 会东县| 新安县| 嵊州市| 得荣县|