let mantra = document.querySelectorAll(".mantra-link"),
toggleHover = function() {
[].map.call(mantra, function(elem) { });
this.classList.remove("inline");
this.classList.add("hover");
this.classList.toggle("hide");
};
[].map.call(mantra, function(elem) {
elem.addEventListener("click", toggleHover, false);
});
$('.switch-checkbox').on('change', function() {
if ($(this).is(":checked")) {
$(this)
.parent('aside')
.parent('span')
.toggleClass("inline hide hover");
}
});
.mantra-link{
postion: relative;
display:inline-block;
border: solid red;
}
aside{
background-color: white;
}
.inline aside{
display: flex;
flex-wrap: wrap;
width: 100%;
border: solid 1px red;
}
.hovercard p{
width: 100%;
}
.hide aside {
display: none; /* Need this in case it's not hovering */
visibility: hidden;
}
.hover aside{
display: flex;
position: absolute;
top: 2.25m;
background-color: white;
border: solid 1px gray;
padding: 20px;
}
.inline{
width: 100% ;
display: block;
width: 100%;
border: blue solid 1px ;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section class="kyu-library-steps">
<h3 class="kyu-library-tag-heading">Instructions</h3>
<ol class="kyu-library-steps-list">
<li class="kyu-library-step">
<div class="kyu-library-text"> <span class="mantra-link hide">Chant the <a href="#">Guru Ram Das Mantra </a>
<aside class="hovercard">
<p>Lots of content about Mantra.</p>
<span class="kyul-embed mantra-inline">Show mantra inline</span>
<input type="checkbox" name="switch" class="switch-checkbox" id="myswitch" unchecked>
<label class="switch-labels" for="myswitch"></label>
</aside>
</span> Lorem ipsum dolor sit amet consectetur adipisicing elit. Minima blanditiis consequuntur animi in quos aperiam voluptates eveniet possimus libero ipsa. Eaque, quisquam! Commodi, sit? Quod dignissimos illo voluptatem dolorem fuga?
</div>
</li>
<li class="kyu-library-step">
<div class="kyu-library-text"> <span class="mantra-link hide">Chant the <a href="#">Guru Ram Das Mantra </a>
<aside class="hovercard">
<p>Lots of content about Mantra.</p>
<span class="kyul-embed mantra-inline">Show mantra inline</span>
<input type="checkbox" name="switch" class="switch-checkbox" id="myswitch" checked>
<label class="switch-labels" for="myswitch"></label>
</aside>
</span> Lorem ipsum dolor sit amet consectetur adipisicing elit. Minima blanditiis consequuntur animi in quos aperiam voluptates eveniet possimus libero ipsa. Eaque, quisquam! Commodi, sit? Quod dignissimos illo voluptatem dolorem fuga?
</div>
</li>
<li class="kyu-library-step">
<div class="kyu-library-text"> <span class="mantra-link hide">Chant the <a href="#">Guru Ram Das Mantra </a>
<aside class="hovercard">
<p>Lots of content about Mantra.</p>
<span class="kyul-embed mantra-inline">Show mantra inline</span>
<input type="checkbox" name="switch" class="switch-checkbox" id="myswitch" unchecked>
<label class="switch-labels" for="myswitch"></label>
</aside>
</span> Lorem ipsum dolor sit amet consectetur adipisicing elit. Minima blanditiis consequuntur animi in quos aperiam voluptates eveniet possimus libero ipsa. <span class="mantra-link hide">Chant the <a href="#">Guru Ram Das Mantra </a>
<aside class="hovercard">
<p>Lots of content about Mantra.</p>
<span class="kyul-embed mantra-inline">Show mantra inline</span>
<input type="checkbox" name="switch" class="switch-checkbox" id="myswitch" unchecked>
<label class="switch-labels" for="myswitch"></label>
</aside>
</span>Eaque, quisquam! Commodi, sit? Quod dignissimos illo voluptatem dolorem fuga?
</div>
</li>
</ol>
</section>