0

私のページでは、画像プレビュー付きのリンクを使用しています。

マウスでリンクすると、プレビュー画像が表示されます。

ここにデモがあります: http://cssglobe.com/lab/tooltip/03/

画像プレビューの読み込み中に gif の読み込みを表示したい。

次のような gif の読み込み: http://i.imgur.com/54cQB45.gif

これが私のJavaScriptコードです。

this.screenshotPreview = function(){   
        /* CONFIG */

                xOffset = 10;
                yOffset = 30;

                // these 2 variable determine popup's distance from the cursor
                // you might want to adjust to get the right result

        /* END CONFIG */
        $("a.screenshot").hover(function(e){
                this.t = this.title;
                this.title = "";       
                var c = (this.t != "") ? "<br/>" + this.t : "";
                $("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");                                                                
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px")
                        .fadeIn("fast");                                               
    },
        function(){
                this.title = this.t;   
                $("#screenshot").remove();
    });
        $("a.screenshot").mousemove(function(e){
                $("#screenshot")
                        .css("top",(e.pageY - xOffset) + "px")
                        .css("left",(e.pageX + yOffset) + "px");
        });                    
};


// starting the script on page load
$(document).ready(function(){
        screenshotPreview();
});

および html コード ;

<a href="Link" class="screenshot" rel="image link">Link Name</a>

どうすればいいですか?何か案は ?

4

1 に答える 1

1

次のコード スニペットのバリエーションを使用して、ロードされたイベントをトリガーできます。

var img = $("<img />").attr('src', 'http://somedomain.com/image.jpg')
    .load(function() {
        if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
            alert('broken image!');
        } else {
            $("#something").append(img);
        }
    });
于 2013-07-27T22:06:33.913 に答える