我有一个具有此结构的HTML页面。
<div class="scrollBoxYe">
<table class="grid">
<tr><td class="wd0"><div id="20110701" class="lcday"><div class="lcleft">Fri 01</div><div class="lcmid">The Sacred Heart of Jesus, solemnity - <a href="#" onclick="window.open('http://evangelizo.org/www/popup-saints.php?language=AM&id=10309&fd=0', '', 'width=500,height=450,top=120,left=120,scrollbars=yes')">St. Gal, Bishop (c. 489-553)</a>, <a href="#" onclick="window.open('http://evangelizo.org/www/popup-saints.php?language=AM&id=10480&fd=0', '', 'width=500,height=450,top=120,left=120,scrollbars=yes')">Bl. Antonio Rosmini, Priest, Founder of the Institute of Charity (1797-1855)</a></div><div class="lcright">Jul</div></div></td>
</tr>
<tr><td class="we0"><div id="20110702" class="lcday"><div class="lcleft">Sat 02</div><div class="lcmid">Immaculate Heart of Mary - Memorial - <a href="#" onclick="window.open('http://evangelizo.org/www/popup-saints.php?language=AM&id=9906&fd=0', '', 'width=500,height=450,top=120,left=120,scrollbars=yes')">St. Bernardino Realino, Priest (1530-1616)</a></div><div class="lcright">Jul</div></div></td>
</tr>
<tr><td class="we0"><div id="20110703" class="lcday"><div class="lcleft">Sun 03</div><div class="lcmid"><a href="#" onclick="window.open('http://evangelizo.org/www/popup-saints.php?language=AM&id=9907&fd=0', '', 'width=500,height=450,top=120,left=120,scrollbars=yes')">St. Thomas, Apostle -Feast</a></div><div class="lcright">Jul</div></div></td>
</tr>
</table>
</div>
<script type="text/javascript">
ScrollCalendar();
</script>
ScrollCalendar函数应滚动到div ID,如20110701,20110702,20110703。
function ScrollCalendar() {
var d = new Date();
calrow = d.formatDate("Ymd");
document.write (calrow);
var offscroll = window.parent.document.getElementById(calrow).offsetTop;
document.write (offscroll);
window.parent.document.getElementById("scrollBoxYe").scrollTop = offscroll;
}
在上面的函数中,正确确定了使用变量calrow检索的div ID。但是,代码没有提供正确的偏移量(offscroll)来滚动div(scrollBoxYe)。这些是我的问题:
感谢。
答案 0 :(得分:1)
有一种更好的滚动方式:element.scrollIntoView()
http://msdn.microsoft.com/en-us/library/ms536730(v=vs.85).aspx
这不是标准的一部分,但根据this,所有浏览器都支持它。