matthew s
matthew s

Reputation: 43

Trying to get iframe to appear on hover

Is there a way for an iframe to appear on hover.

This is what i have:

<div id="sub1" onmouseover="<iframe src="$('#countdown').load('https://days.to/22-january/2017 #countdown');>some text</div>

Upvotes: 3

Views: 10409

Answers (2)

zer00ne
zer00ne

Reputation: 43990

No JS/jQ needed just some CSS transitions and a :hover pseudo-class`

SNIPPET

#ifrm1 {
  opacity: 0;
  transition: opacity 1.5s linear;
}
#trig1:hover + iframe {
  opacity: 1;
  transition: opacity 1.5s linear;
}
<a href='#/' id='trig1'>HOVER</a>
<iframe id='ifrm1' name='ifrm1' src='https://days.to/until/christmas'></iframe>

Upvotes: 7

Michele Riva
Michele Riva

Reputation: 562

Use jQuery! Sorry for the ugly script, I'm sure you can do better :)

$('#idToHover').hover(function(){
  $('#idModal').css("display", "block");
})

$('#idToHover').mouseout(function(){
  $('#idModal').css("display", "none");
})
#idModal{
display: none;  
}
<html>
  <head>
    <script
  src="https://code.jquery.com/jquery-3.1.1.slim.js"
  integrity="sha256-5i/mQ300M779N2OVDrl16lbohwXNUdzL/R2aVUXyXWA="
  crossorigin="anonymous"></script>
  </head>
 
  <body>
   
    <div id="idToHover"> Hello World </div>
    <div id="idModal">
      <iframe src="http://www.w3schools.com"></iframe>
    </div>  
    
  </body>
</html>

Upvotes: 1

Related Questions