我試圖使用Jquery
和Javascript
,因此當客戶端鼠標懸停在PageGridView
上使用的通用圖標時,它將顯示略微偏離圖標的縮略圖圖像。圖標mouseover上的圖像預覽
我借用了我在Techrepublic上找到的代碼。
CSS使用:
<style type="text/css">
#Fullimg{position:absolute;display:none;z-index:-1}
#preview{
position:absolute;
border:3px solid #ccc;
background:#333;
padding:5px;
display:none;
color:#fff;
box-shadow: 4px 4px 3px rgba(103, 115, 130, 1);
}
pre{
display:block;
font-family:Tahoma, Geneva, sans-serif;
font-weight:normal;
padding:7px;
border:3px solid #bae2f0;
background:#e3f4f9;
margin:.5em 0;
overflow:auto;
width:800px;
}
</style>
的Javascript:
<script type="text/javascript" language="javascript">
// Kick off the jQuery with the document ready function on page load
$(document).ready(function(){
imagePreview();
});
// Configuration of the x and y offsets
this.imagePreview = function(){
xOffset = -20;
yOffset = 40;
$("a.preview").hover(function(e){
this.t = this.title;
this.title = "";
var c = (this.t != "") ? "<br/>" + this.t : "";
$("body").append("<p id='preview'><img src='"+ this.link +"' alt='Image preview' />"+ c +"</p>");
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
},
function(){
this.title = this.t;
$("#preview").remove();
});
$("a.preview").mousemove(function(e){
$("#preview")
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
};
</script>
圖標:
<asp:Image ID="imgThumbnail" runat="server" ImageURL="~/Images/imgHover.png" ImageAlign="AbsMiddle" ClientIDMode="Static" CssClass="preview" link='<%# String.Format("~/ConvertImage.ashx?FleetID=" + m_oUserInfo.CurrentFleetID + "&VehicleID={0}&picID={1}&picType=PictureThumb&extention={2}", Eval("VehicleID"), Eval("StoredPictureID"), Eval("PictureExtension"))%>'/>
的代碼也絕對沒有什麼奇怪的是,儘管甚至試圖使它在fiddle工作。近一週來,我一直在我的頭上撞牆,老闆開始討厭我無法工作。
任何幫助或更具代碼效率的方法,將不勝感激。
在瀏覽器控制檯的任何錯誤? –
我對Fiddle上的編碼感到困惑。看起來你正在將一個監聽器應用到$('a.preview'):一個不存在於DOM中的元素,並且不會被我看到的任何jQuery添加。它也似乎在運行你的函數時使用「this」,但這是需要的嗎?爲什麼不通過$ .fn.extend創建一個函數,並使用$('a.preview')來運行它。ImagePreview();並在那裏定義你的鼠標懸停處理程序? – linnium
@JayBlanchard瀏覽器代碼中沒有錯誤,這是令人困惑的部分。 – Trasiva