`
openxtiger
  • 浏览: 147706 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

[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);
        }
    }
};

 

0
3
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics