What's new
  • Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

HTML CSS JS Modal component on Vue.js


Joined
Dec 15, 2015
Messages
5
Reaction
0
Age
23
Create new file on components

modal.vue
Code:
<template>
  <div :id="id" class="modal" aria-hidden="true">
    <div class="modal-dialog">
      <a href="#" class="close" aria-label="Close Modal Box"
        ><i class="fas fa-times"></i
      ></a>
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    id: {
      type: String,
      default: "",
    },
  },
};
</script>

<style lang="scss" scoped>
.modal:before {
  content: "";
  display: none;
  background: rgba(0, 0, 0, 0.6);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
}
.modal:target:before {
  display: block;
}
.modal:target .modal-dialog {
  transform: translate(0, 0);
  top: 20%;
}
.modal-dialog {
  background: #fefefe;
  max-width: 100%;
  margin: 0 10em 0 -5em;
  border-radius: 5px;
  position: fixed;
  z-index: 11;
  min-width: 360px;
  transform: translate(0, -500%);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease-out;
}
.modal-body {
  padding: 20px;
}
.modal-header,
.modal-footer {
  padding: 10px 20px;
}
.modal-header {
  border-bottom: #eeeeee solid 1px;
}
.modal-header h2 {
  font-size: 20px;
}
.modal-footer {
  border-top: #eeeeee solid 1px;
  text-align: right;
}
.close {
  position: fixed;
  top: 0;
  right: 0;
  color: #333;
  margin: 0.1em 0.2em;
}
#close {
  display: none;
}
</style>
how to use?
Code:
<template>
    <div>
     <!--Make sure the id is the same on href  -->
    <a href="#preview-modal">open modal</a>
    <modal id="preview-modal">
        <div>
            <h2>This is the content of modal</h2>
        </div>
    </modal>
    </div>
</template>
import modal from "~/components/modal";
export default {
  components: { modal }
 }
 

Like us on facebook

Online statistics

Members online
686
Guests online
648
Total visitors
1,334

Forum statistics

Threads
879,366
Messages
15,562,726
Members
1,406,723
Top