[Javascript技巧]代碼編輯器的行號,通過hash定位

$.initLineNumbers = function () {
    var hash      = window.location.hash.substring(1),
        container = $.get('container'),
        hasLines, node;

    // Add ids for each line number in the file source view.
    $('.linenums>li').each(function () {
        $(this).set('id', 'l' + (index + 1));
        $(this).addClass('file-line');
        hasLines = true;
    });

    // Scroll to the desired line.
    if (hasLines && /^l\d+$/.test(hash)) {
        if ((node = $.get(hash))) {
            win.scroll(0, node.offset().x);
        }
    }
};

 

發佈了37 篇原創文章 · 獲贊 1 · 訪問量 3513
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章