Modal Template

by James Connolly

HTML

<ul class="parent-list">
	<li id="post-1">Item 1</li>
	<li id="post-2">Item 2</li>
	<li id="post-3">Item 3</li>
	<li id="post-4">Item 4</li>
	<li id="post-5">Item 5</li>
	<li id="post-6">Item 6</li>
</ul>

SCSS

body {
  position: relative;
  
  &.modal-inview {
    overflow: hidden;
  }
}

.highlight {
	color: red;
}

// modal styles

.modal {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 25px;
  width: 100%;
  height: 100%;
  overflow: scroll;
  opacity: 0;
  visibility: hidden;
  background: rgba(0, 0, 0, 0.7);
  transition: all 0.3s ease;
  transition-delay: 0.4s;
  position: fixed;
  left: 0;
  top: 0;
  
  .modal-body {
    display: flex;
    margin: 0 auto;
    width: 100%;
    max-width: 960px;
    background: white;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
    transition: all 0.3s ease;
    transiton-delay: 0;
  }
  
  &.open {
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
    
    .modal-body {
      opacity: 1;
      visibility: visible;
      transform: scale(1);
      transition-delay: 0.2s;
    }
  }
}

.modal-side,
.modal-main{
  display: flex;
  box-sizing: border-box;
}

.modal-side {
  background: blue;
  color: white;
  width: 20%;
  
  section {
    padding: 15px;
  }
}

.modal-main {
  background: pink;
  width: 80%;
  
  section{
    padding: 25px;
    position: relative;
  }
}

.modal-close {
  display: block;
  width: 35px;
  height: 35px; 
  line-height: 35px;
  text-align: center;
  cursor: pointer;
  background: green;
  color: white;
  position: absolute;
  right: 0;
  top: 0;
}



/*--------------------------------------------------------------
# Scrollbar
--------------------------------------------------------------*/

.modall::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

.modall::-webkit-scrollbar-button {
  width: 0px;
  height: 0px;
}

.modall::-webkit-scrollbar-thumb {
  background: #1C3758;
  border-radius: 50px;
}

.modall::-webkit-scrollbar-thumb:hover,
.modall::-webkit-scrollbar-thumb:active {
  background:...

JavaScript

// Get the element, add a click listener...
document.getElementByClassName("parent-list").addEventListener("click", function(e) {
	// e.target is the clicked element!
	// If it was a list item
	if(e.target && e.target.nodeName == "li") {
		// List item found!  Output the ID!
		console.log("List item ", e.target.id.replace("post-", ""), " was clicked!");
	}
});