0

サイトに新しいスライドショーを取り入れようとしています。スライドショーには、"height = "80%"" のオプションを除いて、必要なものがすべて含まれています。つまり、新しいサイトのデザインは Android アプリケーションのように分類されるため、スライドショーをブラウザーに合わせてスケーリングする必要があります。完全に没入型。

スライドショー自体にはこのオプションがないため、ドキュメント/ブラウザ ウィンドウのサイズを 2 秒ごとにチェックし、常に画面に収まるようにスライドショー自体をリロード/サイズ変更する JavaScript コードを作成しています。しかし、問題は、特定のコード文字列をスクリプトに貼り付けた後、javascript がオンロードで 1 回しか実行されず、「setTimeout」を呼び出さないことです。

したがって、問題は setTimeout が実際に動作を停止することです。そのため、次のコード文字列を含めた後、以前は動作していました。

var thescript = document.createElement("script");
thescript.type = "text/javascript";
thescript.innerHTML="jQuery.flashgallery('gallery/ArtGallery.swf', 'gallery/gallery.xml', {width: '100%', height: '"+calcheight+"px', background: '#000000'});";
document.getElementById('galleryid').appendChild(thescript);

完全な JavaScript チェック関数は次のとおりです。

function getDocSpecs() {

    clearTimeout(t);
    var D = Math.max(
        Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
        Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
        Math.max(document.body.clientHeight, document.documentElement.clientHeight));

    var Le = Math.max(
        Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
        Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
        Math.max(document.body.clientWidth, document.documentElement.clientWidth));

    calcheight = (0.80 * D);
    alert(preheight + "_" + prewidth + "_" + D + "_" + Le + "_");
    if (preheight != D || prewidth != Le) {

        var thescript = document.createElement("script");
        thescript.type = "text/javascript";
        thescript.innerHTML = "jQuery.flashgallery('gallery/ArtGallery.swf', 'gallery/gallery.xml', {width: '100%', height: '" + calcheight + "px', background: '#000000'});";
        document.getElementById('galleryid').appendChild(thescript);
    }


    preheight = D;
    prewidth = Le;

    t = setTimeout('getDocSpecs()', 2000);
}

これらの 2 つは互いに気に入らないようです。

var thescript = document.createElement("script");
thescript.type = "text/javascript";
thescript.innerHTML="jQuery.flashgallery('gallery/ArtGallery.swf', 'gallery/gallery.xml', {width: '100%', height: '"+calcheight+"px', background: '#000000'});";
document.getElementById('galleryid').appendChild(thescript);

t = setTimeout('getDocSpecs()', 2000);

最初にスライドショーをロードしてから関数を呼び出し、クリックでアクティブ化されたテキストを追加し、複数の関数を呼び出すなどして、それをだまそうとしました.

4

1 に答える 1

1

この 2 つは互いに影響を与えるべきではありませんが、同時に、実行createElementしようとしている目的で使用する必要はありません。

少し整理し、ビットを明確な機能に分離し、createElementパーツを削除しました。より簡単にデバッグできるようになることを願っています。ただし、それ以外の場合は同じ動作を維持しようとしました。
コメントで述べたように、resizeにイベント リスナーを使用するように変更することもできます。これにより、関数を頻繁に呼び出す必要がなくなります。

var getDocSpecs = (function () {
    var t,
        pre = {h: -1, w: -1},
        getDocSpecs;

    function asyncFlashGallery(p1, p2, p3) {
        return window.setTimeout(function () {jQuery.flashgallery(p1, p2, p3)}, 0);
    }

    function dMax(nx) {
        return Math.max(document.body[nx] || 0, document.documentElement[nx] || 0);
    }

    getDocSpecs = function getDocSpecs() {
        window.clearTimeout(t);
        var D = Math.max(
                dMax('scrollHeight'), dMax('offsetHeight'), dMax('clientHeight')
            ),
            Le = Math.max(
                dMax('scrollWidth'), dMax('offsetWidth'), dMax('clientWidth')
            ),
            calcheight = (0.80 * D);

        alert(pre.h + "_" + pre.w + "_" + D + "_" + Le + "_"); // consider console.log
        if (pre.h !== D || pre.w !== Le) {
            asyncFlashGallery(
                'gallery/ArtGallery.swf',
                'gallery/gallery.xml',
                "{width: '100%', height: '" + calcheight + "px', background: '#000000'}"
            );
        }

        pre.h = D;
        pre.w = Le;

        t = window.setTimeout(getDocSpecs, 2000);
    };
    getDocSpecs.CANCEL = function () {window.clearTimeout(t);}
    return getDocSpecs;
}());
于 2013-04-30T15:38:34.433 に答える