[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년 전 조회 1,359
14년 전 조회 3,325
14년 전 조회 1,676
14년 전 조회 1,381
14년 전 조회 1,378
14년 전 조회 1,635
14년 전 조회 1,547
14년 전 조회 1,457
14년 전 조회 1,957
14년 전 조회 1,368
14년 전 조회 2,005
14년 전 조회 2,391
14년 전 조회 1,359
14년 전 조회 1,508
14년 전 조회 1,339
14년 전 조회 1,500
14년 전 조회 1,929
14년 전 조회 1,628
14년 전 조회 1,752
14년 전 조회 1,551
14년 전 조회 1,724
14년 전 조회 1,308
14년 전 조회 2,171
14년 전 조회 1,501
14년 전 조회 2,252
14년 전 조회 8,999
14년 전 조회 1,588
14년 전 조회 2,429
14년 전 조회 2,170
14년 전 조회 2,421
14년 전 조회 2,792
14년 전 조회 1,387
14년 전 조회 1,525
14년 전 조회 7,316
14년 전 조회 1,483
14년 전 조회 1,421
14년 전 조회 2,599
14년 전 조회 1,482
14년 전 조회 1,471
14년 전 조회 2,938
14년 전 조회 1,547
14년 전 조회 4,459
14년 전 조회 4,592
14년 전 조회 1,950
14년 전 조회 1,501
14년 전 조회 2,181
14년 전 조회 1,456
14년 전 조회 1,758
14년 전 조회 1,343
14년 전 조회 8,245
14년 전 조회 1,881
14년 전 조회 1,285
14년 전 조회 1,441
14년 전 조회 2,139
14년 전 조회 1,589
14년 전 조회 1,451
14년 전 조회 1,533
14년 전 조회 1,455
14년 전 조회 1,307
14년 전 조회 1,420
14년 전 조회 1,429
14년 전 조회 1,416
14년 전 조회 1,477
14년 전 조회 1,725
14년 전 조회 1,726
14년 전 조회 2,000
14년 전 조회 1,599
14년 전 조회 1,529
14년 전 조회 1,430
14년 전 조회 1,377
14년 전 조회 1,376
14년 전 조회 1,557
14년 전 조회 2,777
14년 전 조회 1,434
14년 전 조회 1,756
14년 전 조회 2,920
14년 전 조회 2,043
14년 전 조회 1,781
14년 전 조회 5,532
14년 전 조회 2,727
14년 전 조회 1,541
14년 전 조회 1,460
14년 전 조회 1,422
14년 전 조회 1,310
14년 전 조회 2,587
14년 전 조회 3,922
14년 전 조회 1,395
14년 전 조회 1,583
14년 전 조회 2,578
14년 전 조회 1,419
14년 전 조회 2,077
14년 전 조회 2,419
14년 전 조회 1.1만
14년 전 조회 1,966
14년 전 조회 1,745
14년 전 조회 2,462
14년 전 조회 2,514
14년 전 조회 1,682
14년 전 조회 1,791
14년 전 조회 1,583