简体   繁体   English

图标鼠标悬停的图像预览

[英]image preview on icon mouseover

I'm attempting to use Jquery and Javascript so when a client mouseovers a generic icon used on a PageGridView it will display the thumbnail image slightly offset from the icon. 我正在尝试使用JqueryJavascript因此当客户端鼠标悬停在PageGridView上使用的通用图标时,它将显示略微偏离图标的缩略图图像。

I'm borrowing the code I found on Techrepublic . 我正在借用我在Techrepublic上找到的代码。

CSS Being used: 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: 使用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>

Icon: 图标:

<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"))%>'/>

The code does absolutely nothing oddly, despite even trying to make it work in a fiddle . 代码完全没有什么奇怪的,尽管甚至试图让它在小提琴中工作。 I've been beating my head against the wall on this for almost a week and the boss is starting to get annoyed that I can't get it working. 我差不多一个星期一直在墙上撞墙,老板开始生气,我无法让它发挥作用。

Any help or a more code efficient means of doing this would be greatly appreciated. 任何帮助或代码更有效的方法都将非常感激。

I corrected some basic part in the code. 我纠正了代码中的一些基本部分。 Here is the link: http://fiddle.jshell.net/bpVUk/2/ You can modify now as per your needs. 这是链接: http//fiddle.jshell.net/bpVUk/2/您可以根据需要立即修改。

Code: 码:

        // Kick off the jQuery with the document ready function on page load
    $(document).ready(function () {
        var xOffset = -20;
        var yOffset = 40;
        $('.preview').on('mouseover', function (e) {
            var img = $(this);
            img.t = img.title;
            img.title = "";
            var c = (img.t != "") ? "<br/>" + img.t : "";
            $("body").append("<p id='preview'><img src='" + img.attr('link') + "' alt='Image preview' />" + c + "</p>");
            $("#preview").css({
                "top": (e.pageY - xOffset) + "px",
                    "left": (e.pageX + yOffset) + "px",
                    'display': 'block',
            });
        });
        $('.preview').on('mouseleave', function (e) {
            $('#preview').remove();
        })
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM