简单的jQuery机场文字效果,需要停止,清除更改在飞行
Simple jQuery airport text effect, need to stop, clear change on fly?
我喜欢在这里使用这段简单的代码
http://www.unwrongest.com/projects/airport/
,它将在我的网站上用于天气显示http://www.xaluan.com
的想法是:温度将从00跳转到当前的温度,它看起来很好和活…问题是,当我将温度从C更改为F,或更改温度的位置时,温度将需要更改,然后文本效果也需要更改。
但我试过很多次,甚至使用。stop或。clearque重新启动效果,但没有成功。它搞砸了,有的情况下不运行,有的情况下数组的效果变成了两个数组的合并…我完全迷路了,谢谢你的建议
this is narrow simple code for statup test:
<span id="tempnow" class="tempnow">30</span>
<span onclick="changeC()">°F</span>
<span onclick="changeF()">°C</span>
<script>
// fist time run will be:
$(function($){
$('#tempnow').airport(['00','34']);
});
function changeF () {
$('#tempnow').airport([ '00', '91' ]);
}
function changeC () {
$('#tempnow').airport([ '00', '34' ]);
}
(function($){
$.fn.extend({
airport: function(array) {
var self = $(this);
var chars = ['0','9','8','7','6','5','4','3','2','1','-'];
var longest = 0;
var items = items2 = array.length;
function pad(a,b) { return a + new Array(b - a.length + 1).join(' '); }
$(this).empty();
while(items--)
if(array[items].length > longest) longest = array[items].length;
while(items2--)
array[items2] = pad(array[items2],longest);
spans = longest;
while(spans--)
$(this).prepend("<span class='c" + spans + "'></span>");
function testChar(a,b,c,d){
if(c >= array.length)
setTimeout(function() { testChar(0,0,0,0); }, 1000);
else if(d >= longest)
setTimeout(function() { testChar(0,0,c+1,0); }, 1000);
else {
$(self).find('.c'+a).html((chars[b]==" ")?" ":chars[b]);
setTimeout(function() {
if(b > chars.length)
testChar(a+1,0,c,d+1);
else if(chars[b] != array[c].substring(d,d+1).toLowerCase())
testChar(a,b+1,c,d);
else
testChar(a+1,0,c,d+1);
}, 20);
}
}
testChar(0,0,0,0);
}
});
})(jQuery);
</script>
我把jsbin放在这里,希望有人能通过代码帮助我
http://jsbin.com/onaqis/7/edit#source
谢谢. .
这里有一个简单的解决方法:http://jsfiddle.net/EUKuS/你需要去掉下面一行来打破这个无休止的循环:
if(c >= array.length)
setTimeout(function() { testChar(0,0,0,0); }, 1000); // <----- COMMENT OUT!
else if(d >= longest)
应该工作,但修复插件会更好。
相关文章:
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 单击jquery清除输入值
- 如何在Microsoft VirtualEarth 6.3中使用纯javascript清除整个形状层
- 清除以前的$_GET值或不获取仅隐藏字段的值
- Javascript清除缓存以清除基本身份验证凭据
- 清除启动日期选取器值
- 在 SlickGrid 中编辑后,根据不同列中的另一个单元格清除单元格
- php页面,该页面在清除值后接受输入
- 清除数据并将旧值附加到文本框中
- 使用javascript清除Asp.NET FreeTextBox(RTF文本框)
- 飞行前响应中的访问控制允许标头不允许Angularjs请求标头字段访问控制允许标题
- 如何使Visual Studio自动清除Javascript控制台
- 使用javascript或html本身清除文本字段
- 清除函数中if语句内部不起作用的间隔
- 我应该/如何清除mousemove JQuery事件侦听器
- 从定位目标中的元素中清除类
- 使用查询字符串方法清除浏览器缓存
- 如何在使用AngularJS更改下拉值时清除表单中的数据
- 在Chrome中重新加载页面后清除表单输入值
- 简单的jQuery机场文字效果,需要停止,清除更改在飞行