[jQuery] 실시간 검색어 순위 순서대로 보여주기

http://sir.co.kr/bbs/board.php?bo_table=tiptech&wr_id=3569

이 글을 보고 간단히 만들어봤습니다.


index.html

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
    <head>
        <title>Real-time Rank</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link href="stylesheet.css" media="screen" rel="stylesheet" type="text/css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
        <script src="application.js" type="text/javascript"></script>
        </head>
    <body>
        <div id="content">
            <dl id="rank-list">
                <dt>실시간 급상승 검색어</dt>
                <dd>
                    <ol>
                        <li><a href="#">1 순위</a></li>
                        <li><a href="#">2 순위</a></li>
                        <li><a href="#">3 순위</a></li>
                        <li><a href="#">4 순위</a></li>
                        <li><a href="#">5 순위</a></li>
                        <li><a href="#">6 순위</a></li>
                        <li><a href="#">7 순위</a></li>
                        <li><a href="#">8 순위</a></li>
                        <li><a href="#">9 순위</a></li>
                        <li><a href="#">10 순위</a></li>
                    </ol>
                </dd>
            </dl>
        </div>
    </body>
</html>


stylesheet.css

body {
    font-size: 12px;
    background: #FFF;
    color: #333;
    margin: 0;
}

#content {
    margin: 20px;
    padding: 10px;
    background: #393;
}

#rank-list a {
    color: #FFF;
    text-decoration: none;
}

#rank-list a:hover {
    text-decoration: underline;
}

#rank-list {
    overflow: hidden;
    width: 160px;
    height: 20px;
    margin: 0;
}

#rank-list dt {
    display: none;
}

#rank-list dd {
    position: relative;
    margin: 0;
}

#rank-list ol {
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
    list-style-type: none;
}

#rank-list li {
    height: 20px;
    line-height: 20px;
}


application.js

$(function() {
    var count = $('#rank-list li').length;
    var height = $('#rank-list li').height();

    function step(index) {
        $('#rank-list ol').delay(2000).animate({
            top: -height * index,
        }, 500, function() {
            step((index + 1) % count);
        });
    }

    step(1);
});

|

댓글 8개

올리고 보니 쓸데없는 재귀가 쓰였군요. 바보 같은 코드인데...

window.setInterval로 처리하시는 게 훨씬 안전할 것 같습니다.
생각해 보면 animate가 interval을 쓰기 때문에 그냥 저 코드 그대로 가도 되는군요.

혼자 뭐하는 거지 (...)
혹 네이버,다음,네이트 실시간 검색어 XML 필요하시면
http://bangabmoa.com/api/hitkeyword.php?type=xml
활용하세요.
upcount 말고 downcount가 있는지는 모르겠지만, 일단 upcount가 항상 있다는 가정 하에 적용해봤습니다.

[application.js]

$(function() {
function animateRankList() {
var count = $('#rank-list li').length;
var height = $('#rank-list li').height();

function step(index) {
$('#rank-list ol').delay(2000).animate({
top: -height * index,
}, 500, function() {
step((index + 1) % count);
});
}

step(1);
}

window.yqlCallback = function(data) {
$(data.query.results.channel.data.naver.item).each(function(index, item) {
var text = item.rank + ' - ' + item.keyword + ' [' + item.upcount + ']';
$('#rank-list li a').eq(index).text(text);
});

animateRankList();
}

$('#rank-list li a').text('');

var url = 'http://bangabmoa.com/api/hitkeyword.php?type=xml';
var yql = 'SELECT * FROM xml WHERE url="' + url + '"';

$.ajax({
url: 'http://query.yahooapis.com/v1/public/yql?q=' + yql +
'&format=json&callback=yqlCallback',
dataType: 'script'
});
});
댓글에선 들여쓰기가 하나도 적용 안 되네요.

http://www.google.co.kr/search?q=JavaScript+Beautifier

맘에 드시는 JavaScript Beautifier를 골라 잡아서 돌려주시면 들여쓰기가 깔끔히 적용된 코드를 보실 수 있을 겁니다.
http://jsbeautifier.org/

좋네요~ㅋ 감사합니다.
이거 여러 부분에서 유용하겠네요
오호~감사합니다
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
14년 전 조회 507
14년 전 조회 2,467
14년 전 조회 840
14년 전 조회 541
14년 전 조회 545
14년 전 조회 810
14년 전 조회 718
14년 전 조회 616
14년 전 조회 1,102
14년 전 조회 539
14년 전 조회 1,218
14년 전 조회 1,584
14년 전 조회 552
14년 전 조회 683
14년 전 조회 530
14년 전 조회 680
14년 전 조회 1,116
14년 전 조회 808
14년 전 조회 925
14년 전 조회 750
14년 전 조회 896
14년 전 조회 485
14년 전 조회 1,298
14년 전 조회 651
14년 전 조회 1,403
14년 전 조회 8,148
14년 전 조회 784
14년 전 조회 1,619
14년 전 조회 1,344
14년 전 조회 1,620
14년 전 조회 1,959
14년 전 조회 557
14년 전 조회 700
14년 전 조회 6,491
14년 전 조회 680
14년 전 조회 617
14년 전 조회 1,770
14년 전 조회 668
14년 전 조회 669
14년 전 조회 2,135
14년 전 조회 734
14년 전 조회 3,644
14년 전 조회 3,764
14년 전 조회 1,119
14년 전 조회 709
14년 전 조회 1,384
14년 전 조회 637
14년 전 조회 959
14년 전 조회 542
14년 전 조회 7,361
14년 전 조회 1,046
14년 전 조회 458
14년 전 조회 616
14년 전 조회 1,325
14년 전 조회 758
14년 전 조회 594
14년 전 조회 713
14년 전 조회 644
14년 전 조회 453
14년 전 조회 620
14년 전 조회 607
14년 전 조회 590
14년 전 조회 654
14년 전 조회 895
14년 전 조회 913
14년 전 조회 1,144
14년 전 조회 803
14년 전 조회 719
14년 전 조회 599
14년 전 조회 566
14년 전 조회 557
14년 전 조회 730
14년 전 조회 1,956
14년 전 조회 611
14년 전 조회 925
14년 전 조회 2,096
14년 전 조회 1,197
14년 전 조회 970
14년 전 조회 4,708
14년 전 조회 1,917
14년 전 조회 776
14년 전 조회 643
14년 전 조회 602
14년 전 조회 495
14년 전 조회 1,763
14년 전 조회 3,088
14년 전 조회 584
14년 전 조회 777
14년 전 조회 1,750
14년 전 조회 619
14년 전 조회 1,278
14년 전 조회 1,613
14년 전 조회 1만
14년 전 조회 1,146
14년 전 조회 953
14년 전 조회 1,667
14년 전 조회 1,712
14년 전 조회 882
14년 전 조회 985
14년 전 조회 803
🐛 버그신고