Javascript 滚动到动态高亮显示的表行
当您到达当前月份的页面时,源代码中的javascript将突出显示代表今天的行。如何使页面自动向下滚动到该行?页面是,我得到的脚本是源代码。谢谢Javascript 滚动到动态高亮显示的表行,javascript,scroll,Javascript,Scroll,当您到达当前月份的页面时,源代码中的javascript将突出显示代表今天的行。如何使页面自动向下滚动到该行?页面是,我得到的脚本是源代码。谢谢 var INTENDED_MONTH = 7 //August // INTENDED_MONTH is zero-relative now = new Date().getDate(), rows = document.getElementById('scripture').rows; if (new Date().getMonth() != INT
var INTENDED_MONTH = 7 //August
// INTENDED_MONTH is zero-relative
now = new Date().getDate(),
rows = document.getElementById('scripture').rows;
if (new Date().getMonth() != INTENDED_MONTH) {
// need a value here less than 1, or the box for the first of the month will be in Gold
now = 0.5
};
for (var i = 0, rl = rows.length; i < rl; i++) {
var cells = rows[i].childNodes;
for (j = 0, cl = cells.length; j < cl; j++) {
if (cells[j].nodeName == 'TD'
&& cells[j].firstChild.nodeValue != ''
&& cells[j].firstChild.nodeValue == now) {
rows[i].style.backgroundColor = 'red' // 'ffff99' // '#ffd700' // TODAY - gold
}
}
}
var\u月=7//8月
//预期月为零相对月
现在=新日期().getDate(),
rows=document.getElementById('classic').rows;
如果(新日期().getMonth()!=预定月份){
//此处需要小于1的值,否则本月第一个月的方框将为金色
现在=0.5
};
for(var i=0,rl=rows.length;i
在当前诗篇的函数中使用JQuery:
var INTENDED_MONTH = 7 //August
// INTENDED_MONTH is zero-relative
now = new Date().getDate(),
rows = document.getElementById('scripture').rows;
if (new Date().getMonth() != INTENDED_MONTH) {
// need a value here less than 1, or the box for the first of the month will be in Gold
now = 0.5
};
for (var i = 0, rl = rows.length; i < rl; i++) {
var cells = rows[i].childNodes;
for (j = 0, cl = cells.length; j < cl; j++) {
if (cells[j].nodeName == 'TD'
&& cells[j].firstChild.nodeValue != ''
&& cells[j].firstChild.nodeValue == now) {
rows[i].style.backgroundColor = 'red' // 'ffff99' // '#ffd700' // TODAY - gold
$('html,body').delay(1000).animate({scrollTop:rows[i].offsetTop}, 500);
}
}
}
var\u月=7//8月
//预期月为零相对月
现在=新日期().getDate(),
rows=document.getElementById('classic').rows;
如果(新日期().getMonth()!=预定月份){
//此处需要小于1的值,否则本月第一个月的方框将为金色
现在=0.5
};
for(var i=0,rl=rows.length;i
JSFiddle:
以下代码不需要jQuery。它将ID应用于当前行,以像素为单位计算行的位置,然后滚动到该位置
var INTENDED_MONTH = 7 //August
// INTENDED_MONTH is zero-relative
now = new Date().getDate(),
rows = document.getElementById('scripture').rows;
if (new Date().getMonth() != INTENDED_MONTH) {
// need a value here less than 1, or the box for the first of the month will be in Gold
now = 0.5
};
for (var i = 0, rl = rows.length; i < rl; i++) {
var cells = rows[i].childNodes;
for (j = 0, cl = cells.length; j < cl; j++) {
if (cells[j].nodeName == 'TD'
&& cells[j].firstChild.nodeValue != ''
&& cells[j].firstChild.nodeValue == now) {
rows[i].style.backgroundColor = 'red' // 'ffff99' // '#ffd700' // TODAY - gold
rows[i].setAttribute('id', 'currentRow');
function findPos(obj) {
var curtop = 0;
if (obj.offsetParent) {
do {
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curtop];
}
}
window.scroll(0,findPos(document.getElementById('currentRow')));
}
}
}
var\u月=7//8月
//预期月为零相对月
现在=新日期().getDate(),
rows=document.getElementById('classic').rows;
如果(新日期().getMonth()!=预定月份){
//此处需要小于1的值,否则本月第一个月的方框将为金色
现在=0.5
};
for(var i=0,rl=rows.length;i
它目前正在为我工作
每页都是当前月份。我需要脚本做的是自动向下滚动到我的脚本突出显示为当前日期的行。此外,由于突出显示的日期行是动态发生的,因此无法包含id#currentday。我明白了,我把术语弄错了一点。根据您的需要编辑我的答案。好的,我会尽量说得更清楚。请看html末尾我的源代码中的javascript。javascript已经动态地突出显示(更改样式颜色)今天阅读经文的行。但是,当您转到“八月”页面时,突出显示的行不可见。我无法命名该行,因为要高亮显示的正确行是由脚本动态确定的。我不想要一个按钮来执行它,我需要它与改变行颜色的脚本一起发生。所以,更改颜色,然后在浏览器中移动(滚动)到行。有道理吗?有道理,是的。有没有可能在你的问题中添加一段脚本来照亮这一行?但这并不是@Tedleder在我的解决方案的评论中所要求的平滑滚动。