私が見たすべての例では、「getElementById」を使用して単一の要素を取得し、そのスタイルをその単一の要素に変更しています。
ページ上の一致するすべての要素をスタイルで変更する必要がある状況にあります。フォントサイズ、高さ、幅を変更する必要があります。jQuery は必須ですか、それともオプションですか? 私が質問する理由は、このサイトでは jQuery を使用していないためです。この 1 つのことを達成するためだけにライブラリ全体をダウンロードしたくありません。
更新 例として、ページに次のスタイルの要素がいくつかあるとします。
.outerContact
{
border: 0px;
margin: 7px;
float: left;
padding: 0px;
background: url(/TLSADMIN/UserControls/contactsgrid/trans-shadow.png) no-repeat bottom right; /* Most major browsers other than IE supports transparent shadow. Newer release of IE should be able to support that. */
}
.contactLarge{
height: 163px;
width: 250px;
border: 1px solid #ccc;
border-top: 1px solid #ddd;
font-family: Cambria, Cochin, Georgia, Times, "Times New Roman", serif;
font-size:small;
margin: -5px 5px 5px -5px; /* Offset the image by certain pixels to reveal the shadow, as the shadows are 6 pixels wide, offset it by that amount to get a perfect shadow */
/* Most major browsers other than IE supports transparent shadow. Newer release of IE should be able to support that. */
background-image: url('/TLSADMIN/UserControls/contactsgrid/OutlookContactGradient.png') ;
background-repeat:repeat-x;
background-position: bottom;
padding: 0px; /* Increasing this gives a white border around the image */
background-color: #f2f6f9; /* Background color of the border created by the padding */
border: 1px solid #cecece; /* A 1 pixel greyish border is applied to the white border created by the padding */
display: block; /* IE won't do well without this */
position: relative; /* Make the shadow's position relative to its image */
}
次に、スライダー バーに従って上の要素のサイズを比例的に変更する JavaScript 関数があるとします。私が使用しているスライダー バーは、サード パーティから入手できます: http://aspnetajax.componentart.com/control-specific/slider/features/custom_Scrollbar/WebForm1.aspx
そのスライダーは、ズームイン/ズームアウトする量を決定するために使用する数値を渡します。
function ResizeWindowAccordingToScrollBar(PercentChange)
{
//Locate elements
//Resize fonts, borders, all styles to zoom in/ zoom out.
}
「PercentChange」値をどのように処理することをお勧めしますか? switch ステートメントを使用して、一致する各要素の CSS スタイルを入れ替えることはできますが、他のオプションほどスムーズではない可能性があります。
更新2
また、誰かが私のコードを見たい場合は、自己完結型のサンプルがここにあります: http://www.perfmon.com/download/StackOverflow_ContactsGrid.zip
ComponentArt コントロールをダウンロードする場合は、スクロールバー コードのコメントを自由に外してください。
私の目標は、Outlook 2007 で利用可能なズーム機能を直接エミュレートすることです。