Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>body-scroll-lock demo</title>
    <script src="https://unpkg.com/body-scroll-lock"></script>
  </head>
  <body>
    <h1 style="color: red;">body-scroll-lock demo</h1>
    <h2 style="color: red;">It's not working? Right?</h2>
    
    <a href="https://codepen.io/buptsteve/pen/PvNQjP">How about trying tua-body-scroll-lock? Click me!!!</a>
    
    <button id="btn">click me to show the dialog</button>
    
    <div id="modalOne" class="modal">
      <h2>
        dialog one
        <button id="modalBtn">click me to show another dialog</button>
      </h2>
      
      <p id="targetOne" class="target"></p>
    </div>
    
    <div id="modalTwo" class="modal">
      <h2>
        dialog two
      </h2>
      
      <p id="targetTwo" class="target"></p>
    </div>

    <div id="list"></div>
  </body>
</html>

              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;

  user-select: none;
}
html, body {
  width: 100%;

  text-align: center;
}

#btn {
  position: fixed;
  top: 20px;
  left: 20px;
}
#list {
  margin: 0 20px;
}
#modalTwo > h2 {
    margin-top: 100px;
}

button {
  padding: 6px;

  color: #fff;
  border-radius: 5px;
  background-color: blue;
}
.modal {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;

  display: none;

  padding-top: 40px;

  background-color: rgba(0, 0, 0, 0.5);
}
h2 {
  width: 80%;
  margin: 0 auto;

  color: #000;
  background-color: #fff;
}
.target {
  overflow: scroll;
  -webkit-overflow-scrolling: touch;

  width: 80%;
  height: 400px;
  margin: 0 auto;

  text-align: center;

  color: #000;
  background-color: #fff;
}

              
            
!

JS

              
                var btn = document.getElementById('btn')
var list = document.getElementById('list')
var modalOne = document.getElementById('modalOne')
var modalBtn = document.getElementById('modalBtn')
var targetOne = document.getElementById('targetOne')
var targetTwo = document.getElementById('targetTwo')

var someText = ''
for (var i = 0; i < 100; i++) {
  someText += `<p>${i}</p>`
}
list.innerHTML = someText
targetOne.innerHTML = someText
targetTwo.innerHTML = someText

btn.onclick = function() {
  modalOne.style.display = 'block'
  bodyScrollLock.enableBodyScroll(targetOne)
}
modalBtn.onclick = function() {
  modalTwo.style.display = 'block'
  bodyScrollLock.enableBodyScroll(targetTwo)
}

modalOne.onclick = function(event) {
  if (event.target.id == 'targetOne') return
  if (event.target.id == 'modalBtn') return
  
  modalOne.style.display = 'none'
  bodyScrollLock.disableBodyScroll(targetOne)
}
modalTwo.onclick = function(event) {
  if (event.target.id == 'targetTwo') return
  
  modalTwo.style.display = 'none'
  bodyScrollLock.disableBodyScroll(targetTwo)
}
              
            
!
999px

Console