jQuery水平股票代号与连续循环

时间:2012-04-20 11:31:28

标签: json jsf jquery jquery-plugins

我在jStockticker的html页面中有以下内容。

<div id="ticker" class="stockTicker" style="width: 100%">
    <span class="quote">Stock Quotes: </span>
        <span id="tickerValues-AAPL">
              <span class="up"> 
                <span class="quote">AAPL</span>
                462.12
              </span>
          <span class="down">
                <span class="quote">AAPL</span>
            232.32
               </span>
          <span class="eq"> 
                 <span class="quote">AAPL</span>
          451.52
              </span>
        </span>
            <span id="tickerValues-GOOG">
              <span class="up"> 
                <span class="quote">GOOG</span>
                623.12
              </span>
          <span class="down">
                <span class="quote">GOOG</span>
            502.32
               </span>
          <span class="eq"> 
                 <span class="quote">GOOG</span>
          545.52
              </span>
        </span>
    </div>

并使用jQuery我用ajax更新实时值

$(document).ready(function() {
  $("#ticker").jStockTicker({interval: 45});


         var i = setInterval(function ()
                {

                    $.ajax({
                          type : "POST",
                          url : 'http://localhost:8080/Data.xhtml',
                          dataType : "json",

                          success: function(data) {   

                                    $.each(data, function(i, item) {

                                       if(data[i].LastT == "+"){
                    $("span[id*='tickerValues-"+data[i].Symbol+"']").html("<span class=\"up\"><span class=\"quote\">"+data[i].Symbol+"</span> "+data[i].LastTPrice+"</span>");
                               }else if(data[i].LastT == "-"){
                            $("span[id*='tickerValues-"+data[i].Symbol+"']").html("<span class=\"down\"><span class=\"quote\">"+data[i].Symbol+"</span> "+data[i].LastTPrice+"</span>");
                   }else if(data[i].LastT == " "){
                    $("span[id*='tickerValues-"+data[i].Symbol+"']").html("<span class=\"eq\"><span class=\"quote\">"+data[i].Symbol+"</span> "+data[i].LastTPrice+"</span>");
                   }
                                    }); 

                                  $("#ticker").jStockTicker({interval: 45});

                                  },
                          error : function() {
                            alert("");
                          }
                        });
                    return false;
                }, 6000);

}); 

问题是当更新发生时,滚动条滚动返回到开头并开始滚动而不是在连续滚动时获取更新的值。

1 个答案:

答案 0 :(得分:0)

我意识到这是一个旧帖子,但也许这里看到的工具...... http://www.bitbenderz.com/stockticker/index.html ......可能更符合你的喜好。