- Full-Stack Vue.js 2 and Laravel 5
- Anthony Gore
- 178字
- 2021-07-02 19:57:23
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.
- The Modern C++ Challenge
- Java Web基礎(chǔ)與實例教程(第2版·微課版)
- Magento 2 Development Cookbook
- MATLAB定量決策五大類問題
- Python機器學(xué)習(xí)編程與實戰(zhàn)
- Python之光:Python編程入門與實戰(zhàn)
- Creating Stunning Dashboards with QlikView
- Java程序設(shè)計案例教程
- SQL Server 2016 從入門到實戰(zhàn)(視頻教學(xué)版)
- OpenMP核心技術(shù)指南
- Fastdata Processing with Spark
- JQuery風(fēng)暴:完美用戶體驗
- Web程序設(shè)計:ASP.NET(第2版)
- 現(xiàn)代C:概念剖析和編程實踐
- SSH框架企業(yè)級應(yīng)用實戰(zhàn)