我按照example的要求实现了一个微调器。该代码加载font。在加载页面时加载字体
我的问题是,按钮调用ajax和ajax调用后加载的字体(尽管按钮图标更改首先由javascript请求)。 ajax和font都是从本地服务器调用的。这个服务器不是多任务的,当ajax被调用时,字体不会被加载,直到ajax调用完成。
有没有什么办法强制浏览器加载页面加载时的字体?
$('.btn').on('click', function() {
var $this = $(this);
$this.button('loading');
setTimeout(function() {
$this.button('reset');
}, 800000);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/>
<div style="margin:3em;">
<button type="button" class="btn btn-primary btn-lg " id="load" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing Order">Submit Order</button>
<br>
<br>
<button type="button" class="btn btn-primary btn-lg" id="load" data-loading-text="<i class='fa fa-spinner fa-spin '></i> Processing Order">Submit Order</button>
</div>
UPDATE
我的代码具有这样的结构:
$(button).button('loading');
$.post("/my_page",
JSON.stringify({
param: "1234",
}),
function(data)
{
// ....
$(button).button('reset');
}
)
.fail(function(xhr, status, error)
{
// error handling
$(button).button('reset');
});
在您的示例中,在超时完成后,我看不到加载的字体。在超时之后你想让你的按钮使用不同的字体吗?请澄清一下。 – threeFatCat
@threeFatCat,我想要的是字体加载时立即加载字体。所以,在按下按钮之前,字体被加载。我无法在这里复制C++服务器。请参阅更新。 – ar2015