Javascript按钮打开一个模态;列表

时间:2016-11-09 02:21:54

标签: javascript html css

基本上,我想按一个按钮(与一个人匹配),弹出一个另一个页面的弹出窗口(现在使用模态),这将根据它是一个人而变化。我正在使用w3school的基本模板,我可以使用一个按钮,但是当我尝试在列表中添加一个按钮以匹配某个人时,该模式不会打开。显然,要将每个按钮分配给一个人,他们将需要拥有自己的元素ID,但为什么我甚至无法使用一个按钮来工作? 它在地图上显示""下面的代码段中的按钮。 最重要的"在地图上显示"按钮工作的意义在于它会调出模态,但列表中的相同按钮不起作用。

提前谢谢。



 // Get the modal
 var modal = document.getElementById('myModal');

 // Get the button that opens the modal
 var btn = document.getElementById("myBtn");

 // Get the <span> element that closes the modal
 var span = document.getElementsByClassName("close")[0];

 // When the user clicks the button, open the modal
 btn.onclick = function() {
   modal.style.display = "block";
 }

 // When the user clicks on <span> (x), close the modal
 span.onclick = function() {
   modal.style.display = "none";
 }

 // When the user clicks anywhere outside of the modal, close it
 window.onclick = function(event) {
   if (event.target == modal) {
     modal.style.display = "none";
   }
 }
&#13;
/*DESKTOP*/

/* The Modal (background) */

@media screen and (min-width: 801px) {
  .modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stay in place */
    z-index: 1;
    /* Sit on top */
    width: 100%;
    /* Full width */
    height: 100%;
    /* Full height */
    overflow: hidden;
    /* Enable scroll if needed */
    background-color: rgb(0, 0, 0);
    /* Fallback color */
    background-color: rgba(0, 0, 0, .4);
    /* Black w/ opacity */
    -webkit-animation-name: fadeIn;
    /* Fade in the background */
    -webkit-animation-duration: 0.4s;
    animation-name: fadeIn;
    animation-duration: 0.4s
  }
  /* Modal Content */
  .modal-content {
    position: relative;
    bottom: 0;
    background-color: clear;
    width: 500px;
    height: 700px;
    margin: 0% auto 15% auto;
    /* 5% from the top, 15% from the bottom and centered */
    -webkit-animation-name: slideIn;
    -webkit-animation-duration: 0.4s;
    animation-name: slideIn;
    animation-duration: 0.4s;
    border: solid 2px;
    border-color: #ffc948;
    overflow: hidden;
  }
  /* The Close Button */
  .close {
    color: white;
    float: right;
    font-size: 28px;
    font-weight: bold;
  }
  .close:hover,
  .close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
  }
  .modal-header {
    padding: 2px 16px;
    background-color: #640006;
    color: white;
    height: 2em;
  }
  .modal-body {
    height: 100%;
    width: 100%;
    overflow: hidden;
  }
  /* Add Animation */
  @-webkit-keyframes slideIn {
    from {
      bottom: -300px;
      opacity: 0
    }
    to {
      bottom: 0;
      opacity: 1
    }
  }
  @keyframes slideIn {
    from {
      bottom: -300px;
      opacity: 0
    }
    to {
      bottom: 0;
      opacity: 1
    }
  }
  @-webkit-keyframes fadeIn {
    from {
      opacity: 0
    }
    to {
      opacity: 1
    }
  }
  @keyframes fadeIn {
    from {
      opacity: 0
    }
    to {
      opacity: 1
    }
  }
  * {
    margin: 0;
    padding: 0;
    -webkit-box-sizing: border-box;
  }
}
/*MOBILE*/

/* The Modal (background) */

@media screen and (max-width: 800px) {
  .modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stay in place */
    z-index: 1;
    /* Sit on top */
    width: 100%;
    /* Full width */
    height: 100%;
    /* Full height */
    overflow: hidden;
    /* Enable scroll if needed */
    background-color: rgb(0, 0, 0);
    /* Fallback color */
    background-color: rgba(0, 0, 0, .4);
    /* Black w/ opacity */
    -webkit-animation-name: fadeIn;
    /* Fade in the background */
    -webkit-animation-duration: 0.4s;
    animation-name: fadeIn;
    animation-duration: 0.4s
  }
  /* Modal Content */
  .modal-content {
    position: relative;
    bottom: 0;
    background-color: clear;
    width: 500px;
    height: 700px;
    margin: 0% auto 15% auto;
    /* 5% from the top, 15% from the bottom and centered */
    -webkit-animation-name: slideIn;
    -webkit-animation-duration: 0.4s;
    animation-name: slideIn;
    animation-duration: 0.4s;
    border: solid 2px;
    border-color: #ffc948;
    overflow: hidden;
  }
  /* The Close Button */
  .close {
    color: white;
    float: right;
    font-size: 28px;
    font-weight: bold;
  }
  .close:hover,
  .close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
  }
  .modal-header {
    padding: 2px 16px;
    background-color: #640006;
    color: white;
    height: 2em;
  }
  .modal-body {
    height: 100%;
    width: 100%;
    overflow: hidden;
  }
  /* Add Animation */
  @-webkit-keyframes slideIn {
    from {
      bottom: -300px;
      opacity: 0
    }
    to {
      bottom: 0;
      opacity: 1
    }
  }
  @keyframes slideIn {
    from {
      bottom: -300px;
      opacity: 0
    }
    to {
      bottom: 0;
      opacity: 1
    }
  }
  @-webkit-keyframes fadeIn {
    from {
      opacity: 0
    }
    to {
      opacity: 1
    }
  }
  @keyframes fadeIn {
    from {
      opacity: 0
    }
    to {
      opacity: 1
    }
  }
  * {
    margin: 0;
    padding: 0;
    -webkit-box-sizing: border-box;
  }
}
html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-color: #810008;
}
a.menu-link {
  color: #ffc948;
  display: block;
  text-decoration: none;
  padding-top: 25px;
}
.menu-link span {
  border-bottom: solid 3px #000;
  border-top: double 10px #000;
  display: inline-block;
  height: 4px;
  margin: 0 5px -3px 0;
  width: 30px;
}
.menu-link:hover span {
  border-color: #666;
}
.menu,
.menu > ul,
.menu > ul ul {
  clear: both;
  display: flex;
  flex-flow: column;
  margin: 0;
  width: 70%;
  margin-left: 15%;
  margin-right: 15%;
  padding-left: 15%;
}
.menu.active {
  background: #640006;
  border-bottom: 1px solid #64006;
  border-top: 1px solid #64006;
  margin: 1em 0 1em -12px;
  max-height: 55em;
  width: 100vw;
}
.js .menu > ul ul.active {
  margin: 0;
  max-height: 55em;
  padding: 0;
}
.menu > ul {
  padding: 0;
}
nav li {
  display: inline-block;
  margin: 0;
  position: relative;
}
.menu li a {
  color: #ffc948;
  display: inline-block;
  font-size: 1.04em;
  letter-spacing: .05em;
  line-height: 2.5em;
  text-decoration: none;
}
span.has-subnav {
  display: block;
  font-size: 1em;
  line-height: 2.5em;
  position: absolute;
  right: 20px;
  padding: 0 0.5em;
  top: 0;
}
/*NAV MENU CSS MOBILE */

@media screen and (max-width: 800px) {
  .menu,
  .menu > ul ul {
    margin: 0;
    max-height: 0;
    overflow: hidden;
  }
  .menu li a {
    border-bottom: 1px solid #ffc948;
    display: block;
    padding-left: 15px;
  }
  .menu li li a {
    padding-left: 50px;
  }
  .menu li:last-child a {
    border: none;
  }
  .menu li li:last-child a {
    border-bottom: 1px solid #ffc948;
  }
  .menu li:hover {
    background: #640006;
  }
}
.menu li a:hover {
  background: #ffc948;
  color: black;
}
/*NAV MENU CSS DESKTOP*/

@media screen and (min-width: 801px) {
  nav {
    border-bottom: 1px solid #ffc948;
  }
  a.menu-link {
    display: none;
  }
  .js .menu,
  .js .menu > ul ul {
    max-height: none;
    overflow: visible;
  }
  .js .menu > ul li:hover > ul {
    display: flex;
  }
  .menu ul {
    display: flex;
    flex-flow: row;
    height: 44px;
    justify-content: space-between;
    margin: 0;
    padding: 0;
  }
  .menu span.has-subnav {
    display: none;
  }
  .menu li a:hover {
    color: rgb(0, 0, 0);
  }
  .menu li li a:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #fff;
  }
  .menu ul ul {
    background: #640006;
    border: solid 1px rgba(0, 0, 0, 1);
    border-radius: 2px 2px 5px 5px;
    border-top: solid 2px transparent;
    display: none;
    height: auto;
    overflow: hidden;
    padding: 0;
    position: absolute;
    text-align: left;
    top: 43px;
    width: 150px;
    z-index: 999;
  }
  .chrome .js .menu > ul ul {
    top: 43px;
  }
  .menu ul ul.wide {
    width: 300px;
  }
  .menu ul ul li {
    border-bottom: solid 1px rgba(0, 0, 0, 0.5);
    display: inline-block;
    position: relative;
  }
  .menu > ul ul li:last-child {
    border-bottom: none;
  }
  .menu ul ul li a {
    display: block;
    padding-left: 10px;
  }
}
a {
  text-decoration: none;
  color: #ffc948;
}
ul,
li {
  list-style: none;
  vertical-align: middle;
}
ul.list {
  padding-left: 20px;
}
.alphalist {
  position: fixed;
  right: 0;
  font-size: 12px;
  text-align: center;
  display: inline-block;
  z-index: 2;
  top: auto;
  height: 100%;
}
.list li {
  border-bottom: 1px solid #ffc948;
  line-height: 44px;
  height: 44px;
}
.list .divider {
  font-size: 20px;
  font-weight: bold;
  background: #fafafa;
  box-shadow: -60px 0 0 #fafafa;
  line-height: 28px;
  height: 28px;
  margin-top: -1px;
  position: -webkit-sticky;
  top: 44px;
}
h1 {
  color: #ffc948;
  font-size: 30px;
  font-family: "Baskerville Old Face";
  letter-spacing: 4px;
  text-align: center;
  line-height: 30px;
}
h2 {
  color: #ffc948;
  font-size: 20px;
  font-family: "Baskerville Old Face";
  letter-spacing: 4px;
  text-align: center;
  line-height: auto;
  margin: auto;
}
h3 {
  line-height: 44px;
  height: 44px;
  color: #ffc948;
  width: 100%;
  position: absolute;
  text-align: center;
  z-index: 10;
}
#scrolling {
  padding-top: 44px;
  padding-right: auto;
  overflow: scroll;
  -webkit-overflow-scrolling: touch;
  height: 100%;
  width: 100%;
  position: absolute;
  z-index: 0;
}
@media (-webkit-min-device-pixel-ratio: 2) {
  .list .divider {
    top: 0;
  }
}
.modal-button {
  background-color: #fafafa;
  border: none;
  color: black;
  padding: 8px 16px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: inherit;
  margin: 4px 2%;
  float: right;
  cursor: pointer;
}
.button {
  background-color: #fafafa;
  border: none;
  color: black;
  padding: 8px 16px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: inherit;
  margin: 4px 2%;
  float: right;
  cursor: pointer;
}
&#13;
<button id="myBtn">Show on Map</button>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <div class="modal-header">
      <span class="close">&times</span>
      <h2>Career Fair Map</h2>
    </div>
    <div class="modal-body">
      <iframe src="map.html" width="500px" height="700px">
      </iframe>

    </div>
  </div>
</div>

<div id="scrolling">
  <ul class="list">
    <li class="divider" id="a">A</li>
    <li><a href="#">Amelia Webster</a>
      <button class="button" onclick="alert('## has been added to favorites.')">Favorite</button>
      <button class="button" id="myBtn">Show on Map</button>
      <li><a href="#">Andrew WifKinson</a>
      </li>
      <li><a href="#">Archibald Carrington</a>
        <button class="modal-button" id="myBtn">Show on Map</button>
      </li>
      <li><a href="#">Ariana Clapton</a>
      </li>
      <li><a href="#">Ashley Carter</a>
      </li>
      <li class="divider" id="b">B</li>
      <li><a href="#">Barney Mercer</a>
      </li>
      <li><a href="#">Barry Goodman</a>
      </li>
      <li><a href="#">Brenda Brown</a>
      </li>
      <li><a href="#">Brooke Creighton</a>
      </li>
      <li class="divider" id="c">C</li>
      <li><a href="#">Camilla Kapinksy</a>
      </li>
      <li><a href="#">Caroline Miller</a>
      </li>
      <li><a href="#">Charlotte Gardner</a>
      </li>
      <li><a href="#">Cynthia Monroe</a>
      </li>
      <li class="divider" id="e">E</li>
      <li><a href="#">Elizabeth Abramson</a>
      </li>
      <li><a href="#">Elizabeth Cook</a>
      </li>
      <li><a href="#">Ernie Carter</a>
      </li>
      <li><a href="#">Evelyn Nash</a>
      </li>
      <li class="divider" id="f">F</li>
      <li><a href="#">Fyodor Dostoevsky</a>
      </li>
  </ul>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

在HTML中,id属性是唯一的。因此,您只能绑定到id为myBtn的第一个按钮(我按ID获取元素,我只得到一个,因为这是预期的)。

您将需要使ID唯一并绑定每个点击事件,或者应用一个类,按类获取按钮数组,并绑定数组中的每个按钮。

如果您在每个按钮上设置了一个名为showModalButton的类,则可以使用以下命令获取引用:

var elements = document.getElementsByClassName('showModalButton');

然后迭代元素并绑定:

for(var i = 0; i < elements.length; ++i) {
    elements[i].onclick = function() {
        modal.style.display = "block";
       }
}

答案 1 :(得分:0)

ID应始终是唯一的。

  

id全局属性定义必须具有的唯一标识符(ID)   在整个文件中是独一无二的其目的是识别元素   链接(使用片段标识符),脚本或样式时   (使用CSS)。

这也是你问题的根源。 document.getElementById("theid");将返回第一个元素(也是预期使用此id的唯一元素)。但是,您希望将onclick方法分配给多个按钮。

您应该考虑使用name属性。然后,您可以使用document.getElementsByName("myBtn")循环浏览所有按钮并注册您的监听器。下面的代码包含可以解释我的更改的注释。

&#13;
&#13;
 // Get the modal
 var modal = document.getElementById('myModal');

 // Get all buttons that should opens the modal
 var btns = document.getElementsByName("myBtn");

 // Get the <span> element that closes the modal
 var span = document.getElementsByClassName("close")[0];
 
 // The iframe inside of the Modal
 var modalIFrame = document.getElementById("modal-iframe");

 // When the user clicks the button, open the modal
 for(var i = 0; i < btns.length; i++) {
   (function(i) {
     var btn = btns[i];
     // you should use addEventListener("click", function() {}); here
     btn.onclick = function() {
       // this will set the iframe url every time you press a button and add the "id" of the button that was pressed as a parameter. "id" is just the current index of the for loop for now.
       modalIFrame.setAttribute("src", "map.html?id=" + i);
       modal.style.display = "block";
     }
   })(i);
 }

 // When the user clicks on <span> (x), close the modal
 span.onclick = function() {
   modal.style.display = "none";
 }

 // When the user clicks anywhere outside of the modal, close it
 window.onclick = function(event) {
   if (event.target == modal) {
     modal.style.display = "none";
   }
 }
&#13;
/*DESKTOP*/

/* The Modal (background) */

@media screen and (min-width: 801px) {
  .modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stay in place */
    z-index: 1;
    /* Sit on top */
    width: 100%;
    /* Full width */
    height: 100%;
    /* Full height */
    overflow: hidden;
    /* Enable scroll if needed */
    background-color: rgb(0, 0, 0);
    /* Fallback color */
    background-color: rgba(0, 0, 0, .4);
    /* Black w/ opacity */
    -webkit-animation-name: fadeIn;
    /* Fade in the background */
    -webkit-animation-duration: 0.4s;
    animation-name: fadeIn;
    animation-duration: 0.4s
  }
  /* Modal Content */
  .modal-content {
    position: relative;
    bottom: 0;
    background-color: clear;
    width: 500px;
    height: 700px;
    margin: 0% auto 15% auto;
    /* 5% from the top, 15% from the bottom and centered */
    -webkit-animation-name: slideIn;
    -webkit-animation-duration: 0.4s;
    animation-name: slideIn;
    animation-duration: 0.4s;
    border: solid 2px;
    border-color: #ffc948;
    overflow: hidden;
  }
  /* The Close Button */
  .close {
    color: white;
    float: right;
    font-size: 28px;
    font-weight: bold;
  }
  .close:hover,
  .close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
  }
  .modal-header {
    padding: 2px 16px;
    background-color: #640006;
    color: white;
    height: 2em;
  }
  .modal-body {
    height: 100%;
    width: 100%;
    overflow: hidden;
  }
  /* Add Animation */
  @-webkit-keyframes slideIn {
    from {
      bottom: -300px;
      opacity: 0
    }
    to {
      bottom: 0;
      opacity: 1
    }
  }
  @keyframes slideIn {
    from {
      bottom: -300px;
      opacity: 0
    }
    to {
      bottom: 0;
      opacity: 1
    }
  }
  @-webkit-keyframes fadeIn {
    from {
      opacity: 0
    }
    to {
      opacity: 1
    }
  }
  @keyframes fadeIn {
    from {
      opacity: 0
    }
    to {
      opacity: 1
    }
  }
  * {
    margin: 0;
    padding: 0;
    -webkit-box-sizing: border-box;
  }
}
/*MOBILE*/

/* The Modal (background) */

@media screen and (max-width: 800px) {
  .modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stay in place */
    z-index: 1;
    /* Sit on top */
    width: 100%;
    /* Full width */
    height: 100%;
    /* Full height */
    overflow: hidden;
    /* Enable scroll if needed */
    background-color: rgb(0, 0, 0);
    /* Fallback color */
    background-color: rgba(0, 0, 0, .4);
    /* Black w/ opacity */
    -webkit-animation-name: fadeIn;
    /* Fade in the background */
    -webkit-animation-duration: 0.4s;
    animation-name: fadeIn;
    animation-duration: 0.4s
  }
  /* Modal Content */
  .modal-content {
    position: relative;
    bottom: 0;
    background-color: clear;
    width: 500px;
    height: 700px;
    margin: 0% auto 15% auto;
    /* 5% from the top, 15% from the bottom and centered */
    -webkit-animation-name: slideIn;
    -webkit-animation-duration: 0.4s;
    animation-name: slideIn;
    animation-duration: 0.4s;
    border: solid 2px;
    border-color: #ffc948;
    overflow: hidden;
  }
  /* The Close Button */
  .close {
    color: white;
    float: right;
    font-size: 28px;
    font-weight: bold;
  }
  .close:hover,
  .close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
  }
  .modal-header {
    padding: 2px 16px;
    background-color: #640006;
    color: white;
    height: 2em;
  }
  .modal-body {
    height: 100%;
    width: 100%;
    overflow: hidden;
  }
  /* Add Animation */
  @-webkit-keyframes slideIn {
    from {
      bottom: -300px;
      opacity: 0
    }
    to {
      bottom: 0;
      opacity: 1
    }
  }
  @keyframes slideIn {
    from {
      bottom: -300px;
      opacity: 0
    }
    to {
      bottom: 0;
      opacity: 1
    }
  }
  @-webkit-keyframes fadeIn {
    from {
      opacity: 0
    }
    to {
      opacity: 1
    }
  }
  @keyframes fadeIn {
    from {
      opacity: 0
    }
    to {
      opacity: 1
    }
  }
  * {
    margin: 0;
    padding: 0;
    -webkit-box-sizing: border-box;
  }
}
html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-color: #810008;
}
a.menu-link {
  color: #ffc948;
  display: block;
  text-decoration: none;
  padding-top: 25px;
}
.menu-link span {
  border-bottom: solid 3px #000;
  border-top: double 10px #000;
  display: inline-block;
  height: 4px;
  margin: 0 5px -3px 0;
  width: 30px;
}
.menu-link:hover span {
  border-color: #666;
}
.menu,
.menu > ul,
.menu > ul ul {
  clear: both;
  display: flex;
  flex-flow: column;
  margin: 0;
  width: 70%;
  margin-left: 15%;
  margin-right: 15%;
  padding-left: 15%;
}
.menu.active {
  background: #640006;
  border-bottom: 1px solid #64006;
  border-top: 1px solid #64006;
  margin: 1em 0 1em -12px;
  max-height: 55em;
  width: 100vw;
}
.js .menu > ul ul.active {
  margin: 0;
  max-height: 55em;
  padding: 0;
}
.menu > ul {
  padding: 0;
}
nav li {
  display: inline-block;
  margin: 0;
  position: relative;
}
.menu li a {
  color: #ffc948;
  display: inline-block;
  font-size: 1.04em;
  letter-spacing: .05em;
  line-height: 2.5em;
  text-decoration: none;
}
span.has-subnav {
  display: block;
  font-size: 1em;
  line-height: 2.5em;
  position: absolute;
  right: 20px;
  padding: 0 0.5em;
  top: 0;
}
/*NAV MENU CSS MOBILE */

@media screen and (max-width: 800px) {
  .menu,
  .menu > ul ul {
    margin: 0;
    max-height: 0;
    overflow: hidden;
  }
  .menu li a {
    border-bottom: 1px solid #ffc948;
    display: block;
    padding-left: 15px;
  }
  .menu li li a {
    padding-left: 50px;
  }
  .menu li:last-child a {
    border: none;
  }
  .menu li li:last-child a {
    border-bottom: 1px solid #ffc948;
  }
  .menu li:hover {
    background: #640006;
  }
}
.menu li a:hover {
  background: #ffc948;
  color: black;
}
/*NAV MENU CSS DESKTOP*/

@media screen and (min-width: 801px) {
  nav {
    border-bottom: 1px solid #ffc948;
  }
  a.menu-link {
    display: none;
  }
  .js .menu,
  .js .menu > ul ul {
    max-height: none;
    overflow: visible;
  }
  .js .menu > ul li:hover > ul {
    display: flex;
  }
  .menu ul {
    display: flex;
    flex-flow: row;
    height: 44px;
    justify-content: space-between;
    margin: 0;
    padding: 0;
  }
  .menu span.has-subnav {
    display: none;
  }
  .menu li a:hover {
    color: rgb(0, 0, 0);
  }
  .menu li li a:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #fff;
  }
  .menu ul ul {
    background: #640006;
    border: solid 1px rgba(0, 0, 0, 1);
    border-radius: 2px 2px 5px 5px;
    border-top: solid 2px transparent;
    display: none;
    height: auto;
    overflow: hidden;
    padding: 0;
    position: absolute;
    text-align: left;
    top: 43px;
    width: 150px;
    z-index: 999;
  }
  .chrome .js .menu > ul ul {
    top: 43px;
  }
  .menu ul ul.wide {
    width: 300px;
  }
  .menu ul ul li {
    border-bottom: solid 1px rgba(0, 0, 0, 0.5);
    display: inline-block;
    position: relative;
  }
  .menu > ul ul li:last-child {
    border-bottom: none;
  }
  .menu ul ul li a {
    display: block;
    padding-left: 10px;
  }
}
a {
  text-decoration: none;
  color: #ffc948;
}
ul,
li {
  list-style: none;
  vertical-align: middle;
}
ul.list {
  padding-left: 20px;
}
.alphalist {
  position: fixed;
  right: 0;
  font-size: 12px;
  text-align: center;
  display: inline-block;
  z-index: 2;
  top: auto;
  height: 100%;
}
.list li {
  border-bottom: 1px solid #ffc948;
  line-height: 44px;
  height: 44px;
}
.list .divider {
  font-size: 20px;
  font-weight: bold;
  background: #fafafa;
  box-shadow: -60px 0 0 #fafafa;
  line-height: 28px;
  height: 28px;
  margin-top: -1px;
  position: -webkit-sticky;
  top: 44px;
}
h1 {
  color: #ffc948;
  font-size: 30px;
  font-family: "Baskerville Old Face";
  letter-spacing: 4px;
  text-align: center;
  line-height: 30px;
}
h2 {
  color: #ffc948;
  font-size: 20px;
  font-family: "Baskerville Old Face";
  letter-spacing: 4px;
  text-align: center;
  line-height: auto;
  margin: auto;
}
h3 {
  line-height: 44px;
  height: 44px;
  color: #ffc948;
  width: 100%;
  position: absolute;
  text-align: center;
  z-index: 10;
}
#scrolling {
  padding-top: 44px;
  padding-right: auto;
  overflow: scroll;
  -webkit-overflow-scrolling: touch;
  height: 100%;
  width: 100%;
  position: absolute;
  z-index: 0;
}
@media (-webkit-min-device-pixel-ratio: 2) {
  .list .divider {
    top: 0;
  }
}
.modal-button {
  background-color: #fafafa;
  border: none;
  color: black;
  padding: 8px 16px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: inherit;
  margin: 4px 2%;
  float: right;
  cursor: pointer;
}
.button {
  background-color: #fafafa;
  border: none;
  color: black;
  padding: 8px 16px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: inherit;
  margin: 4px 2%;
  float: right;
  cursor: pointer;
}
&#13;
<!-- Changed id="myBtn" to name="myBtn" -->
<button name="myBtn">Show on Map</button>

<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">
    <div class="modal-header">
      <span class="close">&times</span>
      <h2>Career Fair Map</h2>
    </div>
    <div class="modal-body">
      <iframe id="modal-iframe" src="map.html" width="500px" height="700px">
      </iframe>

    </div>
  </div>
</div>

<div id="scrolling">
  <ul class="list">
    <li class="divider" id="a">A</li>
    <li><a href="#">Amelia Webster</a>
      <button class="button" onclick="alert('## has been added to favorites.')">Favorite</button>
      <!-- Changed id="myBtn" to name="myBtn" -->
      <button class="button" name="myBtn">Show on Map</button>
      <li><a href="#">Andrew WifKinson</a>
      </li>
      <li><a href="#">Archibald Carrington</a>
        <!-- Changed id="myBtn" to name="myBtn" -->
        <button class="modal-button" name="myBtn">Show on Map</button>
      </li>
      <li><a href="#">Ariana Clapton</a>
      </li>
      <li><a href="#">Ashley Carter</a>
      </li>
      <li class="divider" id="b">B</li>
      <li><a href="#">Barney Mercer</a>
      </li>
      <li><a href="#">Barry Goodman</a>
      </li>
      <li><a href="#">Brenda Brown</a>
      </li>
      <li><a href="#">Brooke Creighton</a>
      </li>
      <li class="divider" id="c">C</li>
      <li><a href="#">Camilla Kapinksy</a>
      </li>
      <li><a href="#">Caroline Miller</a>
      </li>
      <li><a href="#">Charlotte Gardner</a>
      </li>
      <li><a href="#">Cynthia Monroe</a>
      </li>
      <li class="divider" id="e">E</li>
      <li><a href="#">Elizabeth Abramson</a>
      </li>
      <li><a href="#">Elizabeth Cook</a>
      </li>
      <li><a href="#">Ernie Carter</a>
      </li>
      <li><a href="#">Evelyn Nash</a>
      </li>
      <li class="divider" id="f">F</li>
      <li><a href="#">Fyodor Dostoevsky</a>
      </li>
  </ul>
</div>
&#13;
&#13;
&#13;