【发布时间】:2017-06-11 02:17:45
【问题描述】:
我想创建一个货币代码。查询从 yahoo Finance API 检索值并将它们显示为文本。主要问题是文本末尾的空白。选框脚本marquee plugin 解决了差距问题。 setInterval 会打乱移动文本,因为它从头开始。
$(document).ready(function() {
//StockPriceTicker();
setInterval(StockPriceTicker, 5000);
});
function StockPriceTicker() {
var Symbol = "",
CompName = "",
Price = "",
ChnageInPrice = "",
PercentChnageInPrice = "";
var CNames = "^FTSE,HSBA.L,SL.L,BATS.L,BLND.L,FLG.L,RBS.L,RMG.L,VOD.L";
var flickerAPI = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22" + CNames + "%22)&env=store://datatables.org/alltableswithkeys";
var StockTickerHTML = "";
var StockTickerXML = $.get(flickerAPI, function(xml) {
$(xml).find("quote").each(function() {
Symbol = $(this).attr("symbol");
$(this).find("Name").each(function() {
CompName = $(this).text();
});
$(this).find("LastTradePriceOnly").each(function() {
Price = $(this).text();
});
$(this).find("Change").each(function() {
ChnageInPrice = $(this).text();
});
$(this).find("PercentChange").each(function() {
PercentChnageInPrice = $(this).text();
});
StockTickerHTML += "<span>" + CompName + " " + Price + "</span>";
});
$(".marquee div").html(StockTickerHTML);
//$("#dvStockTicker").jStockTicker({interval: 30, speed: 2});
});
}
body {
margin: 20px;
}
.marquee {
height: 25px;
width: 420px;
overflow: hidden;
position: relative;
}
.marquee div {
display: block;
width: 200%;
height: 30px;
position: absolute;
overflow: hidden;
animation: marquee 5s linear infinite;
}
.marquee span {
float: left;
width: 50%;
}
@keyframes marquee {
0% {
left: 0;
}
100% {
left: -100%;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="marquee">
<div>
</div>
</div>
提前致谢。
【问题讨论】:
-
没有实际运行的东西很难,尽管我立即反应的一件事是
.marquee span { float: left; width: 50%; }。删除width: 50%或将其更改为.marquee span { display: inline-block; }可能会解决您的问题,因为这样做会使span适应其内容 -
我知道我尝试了很多都没有运气。我希望有人能提供帮助。
-
您能否让我知道给出的答案有什么问题,以便我能够进行调整并让您接受?
标签: jquery html css currency ticker