0

今月のページに到達すると、ソースコードのjavascriptが今日を表す行を強調表示します。ページをその行まで自動的にスクロールダウンさせるにはどうすればよいですか?ページはhttp://www.itsmyturnnow.com/HWC/BRP/08.htmで、与えられたスクリプトはソースコードです。ありがとう。

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
        }
    }
}
4

2 に答える 2

1

現在の詩篇を強調する関数で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);

        }

    }
}

JSFiddle: http: //jsfiddle.net/QT3v5/22/ </ p>

于 2012-08-23T17:21:28.953 に答える
0

次のコードは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')));
        }
    }
}

それは現在私のために働いています。

デモ

于 2012-08-24T02:26:16.820 に答える