JSFiddle - React, Tailwind, and code Playground
HTML
<div id="openModal1" class="modalDialog" data-modalorder="1">
<div>
<a href="#close" title="Close">X</a>
<h1>Content modal 1</h1>
<input type="button" onclick="start()" value="Start">
</div>
</div>
<div id="openModal2" class="modalDialog" data-modalorder="2">
<div>
<a href="#close" title="Close">X</a>
<h1>Content modal 2</h1>
<input type="button" onclick="btn_next()" value="Next">
</div>
</div>
<div id="openModal3" class="modalDialog" data-modalorder="3">
<div>
<a href="#close" title="Close">X</a>
<h1>Content modal 3</h1>
<input type="button" onclick="" value="Next">
</div>
</div>
<input type="button" onclick="btn_reset()" value="Reset">
CSS
.modalDialog {
position: fixed;
font-family: 'Poppins', sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 99999;
opacity: 0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalDialog:target {
opacity: 1;
pointer-events: auto;
}
.modalDialog>div {
width: 500px;
position: relative;
margin: 10% auto;
padding: 26px;
border-radius: 2em;
background: #fff;
}
JavaScript
const openModal1 = () => {
window.location.href = "#openModal1";
}
const openModal2 = () => {
window.location.href = "#openModal2";
}
const openModal3 = () => {
window.location.href = "#openModal3";
}
function start(){
openModal2();
}
const btn_next = () =>{
openModal3();
}
const settingName = "page"; //name of the setting that will be stored in localStorage
init();
function init()
{
//listen for hash change event
window.addEventListener("hashchange", e =>
{
//remove #
let page = location.hash.substring(1);
if (page != "close")
localStorage.setItem(settingName, page); //save current page hash
});
let page = localStorage.getItem(settingName);
if (page)
location.hash = "#" + page;
else
window.location.href = "#openModal1"; //default page
}
function btn_reset()
{
localStorage.removeItem(settingName);
}