0

私はネット上でこのコードを見つけました、そしてそれは私にとって非常に特別です....しかし、私はそれがもう少し特別である必要があります...

このコードは複数のdivでは機能しません。コードを複製して機能させ、クラス名fmornewswrapをnewsrap2などに変更する必要があります。その結果、私のような雑誌サイトのコードが大量に発生します。

誰かがこのコードを複数のdivで機能させるために何をするのか知っていますか?

PS、私は現時点で私のheader.phpでこれらの15のようになりました

$(document).ready(function() {
    var originalFontSize = 11.8;
    var sectionWidth = $('#newswrap8').width();

    $('#newswrap8 span').each(function(){
        var spanWidth = $(this).width();
        var newFontSize = (sectionWidth/spanWidth) * originalFontSize;
        $(this).css({"font-size" : newFontSize, "line-height" : newFontSize/0.9 + "px"});
    });
});

これが私が使用するHTMLコードです

<div style="width:300px;">
<h3 id="newswrap8" style="margin:0px; font-size:12px;">
<span>
<a href="http://www.thelink.no">This is the page title</a>
</span>
</h3>
</div>
4

1 に答える 1

1

html-markupなしでテストするのは難しいですが、アイデアは次のとおりです。

$(document).ready(function(){
    var originalFontSize = 11.8;
    $('[id^="newswrap"]').each(function(){
        var elm = $(this),
            sectionWidth = elm.width();

        elm.find('span').each(function(){
            var spanWidth = $(this).width();
            var newFontSize = (sectionWidth/spanWidth) * originalFontSize;
            $(this).css({"font-size" : newFontSize, "line-height" : newFontSize/0.9 + "px"});
        });
    });
}); 
于 2012-10-03T20:45:59.220 に答える