0

htmlドキュメント(本の章)を取り、それをページ(DIVの配列で、それぞれがDIVの所定の寸法内に収まるhtmlコンテンツのページを含む)に分割したいと思います。私は次のコードでDOMを歩きます(このサイトにあります!)。

function walk(node, func)
{
    func(node);
    node = node.firstChild;
    while (node)
    {
        walk(node, func);
        node = node.nextSibling;
    }
};

func関数はtestと呼ばれ、以下にあります。

function test(node)
{
    var copy=node.cloneNode(false);

    currentPageInArray.appendChild(copy);

    //Test if we still fit
    if( $(currentPageInArray).height() <= maxPageHeight )
    {
        //All good
    }
    else
    {
        //We dont fit anymore 
        //Remove node that made us exceed the height
        currentPageInArray.removeChild(copy);

        createNewPage();
        currentPageInArray.appendChild(copy); //into new page
    }
}

ページは正しく生成されますが、斜体、太字、ヘッダーなどのすべてのスタイルが失われます。clone(true)を実行しようとすると、多くの要素が複数回複製されます。どうすればこれを修正できますか?前もって感謝します。

4

1 に答える 1

1

currentStyle (IE<9) またはgetComputedStyle (その他)を使用して、すべての要素の現在のレイアウトを取得し、複製された要素に適用することができます。

于 2011-07-30T03:08:30.867 に答える