【发布时间】:2019-10-15 00:18:36
【问题描述】:
当淡入应该使用 Google Fonts 字体设置样式的文本时,我想不出一种方法来防止出现未设置样式的内容。
看起来 fonts.googleapis.com 会在页面加载时加载,但直到文本应该淡入时才会加载 fonts.gstatic.com,这会导致文本出现短暂且难看的闪烁Times New Roman 或任何默认字体,然后才突然正确设置样式。
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Quicksand&display=swap" rel="stylesheet">
<!-- Static CSS -->
<link rel='stylesheet' type='text/css' href="main.css"/>
</head>
<body>
<div>
<button id="startButton">Start</button>
</div>
<div id="textDiv">
<p id="textContents"></p>
</div>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" crossorigin="anonymous"></script>
<!-- Static JavaScript -->
<script src="main.js"></script>
</body>
CSS
#textDiv {
font-size: 40px;
font-family: 'Quicksand';
}
Javascript
var textDiv = $('#textDiv');
var text = $('#textContents');
var button = $('#startButton');
// handle click and add text
button.bind("click", function() {
textDiv.hide();
text.html("<p>Hello</p>");
textDiv.fadeIn();
})
https://jsfiddle.net/eshapiro42/xmf23uqw/15/
任何帮助弄清楚如何防止这种情况将不胜感激!
【问题讨论】:
-
请问您使用的是哪种浏览器?
-
我使用的是 Google Chrome 版本 77.0.3865.90。
标签: javascript jquery html css fadein