2013-04-14 27 views

回答

1

當然,你可以替換你想要的任何HTML內容。爲了更容易處理事件處理程序(鼠標懸停在您的案例中),我建議您查看一些現有的Javascript庫,如jQuery

+0

你能舉個例子嗎?,我試圖改變這個圖像:http://i.imgur.com/sjSSr.jpg 進入這個視頻: http://www.youtube.com/watch?v=但我很新的JavaScript(我知道的HTML,CSS) – Edd

+1

有一些HTML內容替換這裏的例子:http://api.jquery.com/replaceWith/ - 爲您的具體情況,你會添加圖像該頁面,然後有一個'mouse over'事件處理程序綁定到'img'元素。然後觸發jQuery的'replaceWith'方法將其替換爲嵌入式YouTube視頻 –

+0

下面給出了另一種解決方案,其中您在youtube視頻之上顯示圖像(使用CSS)。然後'mouse over'事件應該在'img'標籤上調用'hide'(仍然假設你會使用jQuery);)祝你好運! –

0

使用jQuery和一些CSS:

DEMO:http://jsfiddle.net/3SQtS/

<!-- HTML --> 
<div class="replacement"> 
    <img class="top-img" src="http://placekitten.com/560/315" alt="Kitten"> 
    <iframe class="video" width="560" height="315" src="http://www.youtube.com/embed/H93n-k3SkiQ" frameborder="0" allowfullscreen></iframe> 
</div> 

/* CSS */ 
.replacement { 
    position: relative; 
} 
.top-img { 
    position: absolute; 
} 

// jQuery 
jQuery(document).ready(function($) { 
    $('.replacement .top-img').on('mouseenter', function() { 
     $(this).fadeOut(500); 
    }); 
}); 
+0

謝謝,這是完美的 – Edd

相關問題