【发布时间】:2019-08-16 20:36:45
【问题描述】:
我试图通过添加类来增加点击 jquery 的字体大小,但面临一个非常奇怪的问题。文本在变大时开始抖动。谁能给我一个解决方案并向我解释为什么会这样?实际上,我已经尝试过 scale 并且我的文本在 transform: scale 上没有晃动,但我不想在那里缩放。它应该通过字体大小来解决。
gif 画质不流畅,但正如您所见,它在上下晃动。
这是代码的工作示例。
$("div h3").click(function() {
$("div h3").removeClass("active");
$(this).addClass("active");
})
body {
font-family: 'Roboto', sans-serif;
}
div {
}
div h3 {
font-size:40px;
font-weight:800;
opacity:0.3;
margin:0;
transition:0.4s ease all;
}
div h3.active {
font-size:60px;
opacity:1;
transition:0.4s ease all;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900&display=swap" rel="stylesheet">
<div>
<h3>Hello</h3>
<h3>Hello</h3>
<h3>Hello</h3>
</div>
【问题讨论】:
-
既然你指出了这个例子,我可以看到很多东西在我的屏幕上晃动。
-
我猜这可能与尺寸变化有关。您可以尝试更改字体大小:60px;到:字体大小:40px;如果它仍然发生,请告诉我?
-
@ZacharyMcGee 当然,让我快速检查一下。
-
如果您尝试
transform: scale(1.5)而不是更改字体大小,还会发生这种情况吗? -
默认字体大小为 40px,如果我将活动字体大小从 60px 更改为 40px,则它什么也不做。我的意思是字体大小将保持不变!不是吗?
标签: javascript html css