2010-06-06 106 views
1

你知道任何教程或腳本顯示一個圖片時mousemove通過HTML文本?當鼠標移動到jquery文本上時顯示圖片?

+0

當你說 「鼠標移動」 ,你的意思是指針懸停在文本上?或者你的意思是隻在鼠標移動時才顯示圖像?你能提供更多細節嗎? – user113716 2010-06-06 15:01:18

+0

將光標懸停在文本 – DomingoSL 2010-06-06 15:02:25

+0

上,當您指的是顯示圖片時,您的意思是刪除文本,然後顯示pictute或在其他地方顯示圖片 – Starx 2010-06-06 15:05:58

回答

2

一個基本的例子使用jQuery將是這樣的:

CSS

#myImage { 
    display:none; 
}​ 

HTML

<span class='pictureTrigger'>some text</span> 

<img id='myImage' src='/path/to/image' />​ 

jQuery的

$(function() { // Makes sure DOM loads before code is run 

    $('.pictureTrigger').hover( // Assign event handlers for mouseenter/mouseleave 

     function() { $('#myImage').show(); }, // Find myImage and show it on mouseenter 
     function() { $('#myImage').hide(); } // Find myImage and hide it on mouseleave 
    ); 

}); 

很難提供更好的回答問題中的更多細節。

其基本思想是文本包含在span中,該文本有一個名爲pictureTrigger的類。雖然可以命名任何東西。

懸停事件(實際上是兩個事件的簡寫,mouseentermouseleave)被添加到pictureTrigger類的所有元素。

這兩個函數分別代表mouseentermouseleave事件。事件處理函數使用ID myImage找到img,並顯示/隱藏它。


相關jQuery的文檔:

-1

Google for tooltip plugin。有很多。

相關問題