2017-08-01 45 views
0

我試圖編碼圖像,轉向不同的圖像,通過懸停在它上面。 通過點擊圖像,一個嵌入式視頻彈出(在燈箱中)。圖像與懸停效果,當你點擊YouTube視頻應該彈出一個燈箱

我試過幾種不同的東西。這是我現在的代碼。希望有人可以幫助我編寫一個嵌入式YouTube視頻彈出的燈箱,並將其懸停在它上面。 順便說一句,我的目標是這樣的頁面 - >https://www.garyvaynerchuk.com/

感謝你已經

<!DOCTYPE html> 
<html> 
<head> 
<style> 
.container { 
    position: relative; 
    width: 50%; 
} 

.image { 
    display: block; 
    width: 50%; 
    height: auto; 
} 

.overlay { 
    position: absolute; 
    top: 0; 
    bottom: 0; 
    left: 0; 
    right: 0; 
    height: 100%; 
    width: 100%; 
    opacity: 0; 
    transition: .3s ease; 

} 

.container:hover .overlay { 
    opacity: 1; 
} 

.image2 { 
    display: block; 
    width: 50%; 
    height: auto; 
} 
</style> 
</head> 
<body> 


<div class="container"> 
    <a href="https://www.youtube.com/watch?v=18AgmjVPEqc"> 
    <img src="http://politsatire.com/wp-content/uploads/2017/08/playbutton_before.png" alt="Avatar" class="image"> 
    <div class="overlay"> 
    <img src="http://politsatire.com/wp-content/uploads/2017/08/playbutton.png" alt="Avatar" class="image2"> 
    </div> 
</div> 

</body> 
</html> 
+0

非常感謝您的回答。不幸的是,這兩個提示並沒有真正解決。可能是因爲我用wordpress做這個項目,它不能很好地與JavaScript或jQuery相處。我現在通過使用插件「easy fancy box」解決了這個問題,並將以下代碼添加到我以前的代碼中。 Yannick

回答

0

HTML CSS &是不夠的,使用情態動詞,你需要了Javascript,以處理所有相關事件。

// 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 on 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"; 
 
    } 
 
}
/* The Modal (background) */ 
 
.modal { 
 
    display: none; /* Hidden by default */ 
 
    position: fixed; /* Stay in place */ 
 
    z-index: 1; /* Sit on top */ 
 
    left: 0; 
 
    top: 0; 
 
    width: 100%; /* Full width */ 
 
    height: 100%; /* Full height */ 
 
    overflow: auto; /* Enable scroll if needed */ 
 
    background-color: rgb(0,0,0); /* Fallback color */ 
 
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ 
 
} 
 

 
/* Modal Content/Box */ 
 
.modal-content { 
 
    background-color: #fefefe; 
 
    margin: 15% auto; /* 15% from the top and centered */ 
 
    padding: 20px; 
 
    border: 1px solid #888; 
 
    width: 80%; /* Could be more or less, depending on screen size */ 
 
} 
 

 
/* The Close Button */ 
 
.close { 
 
    color: #aaa; 
 
    float: right; 
 
    font-size: 28px; 
 
    font-weight: bold; 
 
} 
 

 
.close:hover, 
 
.close:focus { 
 
    color: black; 
 
    text-decoration: none; 
 
    cursor: pointer; 
 
}
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
</head> 
 
<body> 
 

 
<h2>Modal Example</h2> 
 

 
<!-- Trigger/Open The Modal --> 
 
<button id="myBtn">Open Modal</button> 
 

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

 
    <!-- Modal content --> 
 
    <div class="modal-content"> 
 
    <span class="close">&times;</span> 
 
    <p>Some text in the Modal..</p> 
 
    </div> 
 

 
</div> 
 

 
</body> 
 
</html>

你需要這個例子適應您的需求。

原始代碼:https://www.w3schools.com/howto/howto_css_modals.asp