我见过的所有示例都使用“getElementById”来获取单个元素,然后为该单个元素更改该样式。
我处于需要使用样式修改页面上所有匹配元素的情况。我需要更改字体大小、高度和宽度。我该怎么做,jQuery 是必需的还是可选的?我问的原因是因为这个站点不使用 jQuery,我宁愿不下载整个库只是为了完成这件事。
更新 例如,假设我在页面上有几个具有这种样式的元素:
.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 函数,它将根据滑块按比例调整上面的元素的大小。我正在使用的滑块可从此处的第 3 方获得: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 中可用的缩放功能