0

画像の 1 つを読み込んで配置する際に小さな問題があります。最小のもの。SpaceGalleryスクリプト(http://www.eyecon.ro/spacegallery/)を使用しています。

読み込みは良好ですが、大きな画像の隅に配置したいのですが、ページを初めて読み込むとき、ページを再読み込みすると配置されません。すべて問題ありませんが、最初の読み込みが間違っています。

画面は次のとおりです。サイトを更新せずに最初の読み込みを行います。

最初のロードhttp://derivativationofln.com/withoutload.png

2番目と次のロード:

セカンドロード http://derivativeofln.com/withload.png

私のHTML:

    <div id="myGallery" class="spacegallery">   

    <img class="imaz" src=http://derivativeofln.com/magnifier.jpg />
    <img class="aaa" src=images/bw1.jpg alt="" atr1="bw1" />
    <img class="aaa" src=images/bw2.jpg alt="" atr1="bw2" />
    <img class="aaa" src=images/bw3.jpg alt="" atr1="bw3" />

            </div>      

私のCSS:

#myGallery0 {
width: 100%;
height: 300px;
 }

#myGallery0 img {
border: 2px solid #52697E;
 }

a.loading {
background: #fff url(../images/ajax_small.gif) no-repeat center;
}

.imaz {
 z-index: 10000; 
}


.imaz img{
position: absolute;
left:10px;
top:10px;
z-index: 10000;
width: 35px;
height: 35px;   
}

私のJqueryメインスクリプトファイル:(最初の配置手順は一番下にあるので、自由に下にスクロールしてください:))

(function($){
   EYE.extend({

    spacegallery: {



        animated: false,

        //position images 
        positionImages: function(el) {

            var top = 0;

            EYE.spacegallery.animated = false;
            $(el)
                .find('a')
                    .removeClass(el.spacegalleryCfg.loadingClass)
                    .end()
                    .find('img.aaa')
                    .removeAttr('height')
                    .each(function(nr){
                        var newWidth = this.spacegallery.origWidth - (this.spacegallery.origWidth - this.spacegallery.origWidth * el.spacegalleryCfg.minScale) * el.spacegalleryCfg.asins[nr];

                        $(this)
                            .css({
                                top: el.spacegalleryCfg.tops[nr] + 'px',
                                marginLeft: - parseInt((newWidth + el.spacegalleryCfg.border)/2, 10) + 'px',
                                opacity: 1 - el.spacegalleryCfg.asins[nr]
                            }) 
                            .attr('width', parseInt(newWidth));
                        this.spacegallery.next = el.spacegalleryCfg.asins[nr+1];
                        this.spacegallery.nextTop = el.spacegalleryCfg.tops[nr+1] - el.spacegalleryCfg.tops[nr];
                        this.spacegallery.origTop = el.spacegalleryCfg.tops[nr];
                        this.spacegallery.opacity = 1 - el.spacegalleryCfg.asins[nr];
                        this.spacegallery.increment = el.spacegalleryCfg.asins[nr] - this.spacegallery.next;
                        this.spacegallery.current = el.spacegalleryCfg.asins[nr];
                        this.spacegallery.width = newWidth;
                    })

        },


        //constructor
        init: function(opt) {
            opt = $.extend({}, EYE.spacegallery.defaults, opt||{});
            return this.each(function(){
                var el = this;
                if ($(el).is('.spacegallery')) {
                    $('<a href="#"></a>')
                        .appendTo(this)
                        .addClass(opt.loadingClass)
                        .bind('click', EYE.spacegallery.next);

                    el.spacegalleryCfg = opt;
                    var listunia, images2 = [], index;
                    listunia = el.getElementsByTagName("img");

                    for (index = 1; index < listunia.length; ++index) {
                        images2.push(listunia[index]);
                    } 


                    el.spacegalleryCfg.images = images2.length;             
                    el.spacegalleryCfg.loaded = 0;
                    el.spacegalleryCfg.asin = Math.asin(1);
                    el.spacegalleryCfg.asins = {};
                    el.spacegalleryCfg.tops = {};
                    el.spacegalleryCfg.increment = parseInt(el.spacegalleryCfg.perspective/el.spacegalleryCfg.images, 10);
                    var top = 0;

                    $('img.aaa', el)
                        .each(function(nr){
                            var imgEl = new Image();
                            var elImg = this;

                            el.spacegalleryCfg.asins[nr] = 1 - Math.asin((nr+1)/el.spacegalleryCfg.images)/el.spacegalleryCfg.asin;
                            top += el.spacegalleryCfg.increment - el.spacegalleryCfg.increment * el.spacegalleryCfg.asins[nr];
                            el.spacegalleryCfg.tops[nr] = top;
                            elImg.spacegallery = {};
                            imgEl.src = this.src;
                            if (imgEl.complete) {

                                el.spacegalleryCfg.loaded ++;
                                elImg.spacegallery.origWidth = imgEl.width;
                                elImg.spacegallery.origHeight = imgEl.height
                            } else {
                                imgEl.onload = function() {
                                    el.spacegalleryCfg.loaded ++;
                                    elImg.spacegallery.origWidth = imgEl.width;
                                    elImg.spacegallery.origHeight = imgEl.height
                                    if (el.spacegalleryCfg.loaded == el.spacegalleryCfg.images) {

                                        EYE.spacegallery.positionImages(el);

                                    }
                                };
                            }
                        });




                    el.spacegalleryCfg.asins[el.spacegalleryCfg.images] = el.spacegalleryCfg.asins[el.spacegalleryCfg.images - 1] * 1.3;
                    el.spacegalleryCfg.tops[el.spacegalleryCfg.images] = el.spacegalleryCfg.tops[el.spacegalleryCfg.images - 1] * 1.3;
                    if (el.spacegalleryCfg.loaded == el.spacegalleryCfg.images) {


                            if(el.spacegalleryCfg.images == 3){
                            $('img.imaz', this).css('top', '27px'); // HERE IS POSITIONING OF MY IMAGES, WHEN SCRIPT LOADS FOR THE FIRST TIME!
                            $('img.imaz', this).css('left', (($(el).find('img.aaa:last').width())/2 + 77) + 'px' );
                            }
                            else if(el.spacegalleryCfg.images==2){
                                $('img.imaz', this).css('top', '33px');     
                                $('img.imaz', this).css('left', (($(el).find('img.aaa:last').width())/2 + 77) + 'px' ); // HERE IT ENDS:)
                            }

                        EYE.spacegallery.positionImages(el);
                    }
                }
            });
        }
    }
});
})(jQuery);
4

1 に答える 1

0

これは、html で画像のサイズ (幅と高さ) を指定しようとするキャッシュのようです。これは、最初の読み込み (キャッシュにない画像) では、ブラウザーは読み込み後のサイズしか認識せず、配置が正しくない可能性があるためです。

別の方法として、ドキュメントがロードされたときにポジショニング コードを実行できます。

$(document).ready(«your poisitioning function here»)

そのjquery準備機能については、 http: //api.jquery.com/ready/を参照してください

于 2012-04-30T09:23:38.570 に答える