我想文字效果,如文字增加大小和减少大小循环没有限制使用JavaScript
JavaScript:
function fontSizer() {
if (!document.getElementById("font").style.fontSize) {
document.getElementById("font").style.fontSize = "15px";
}
if (document.getElementById("font").style.fontSize == "15px") {
document.getElementById("font").style.fontSize = "10px";
} else {
document.getElementById("font").style.fontSize = "15px"
}
}HTML:
<p onload="fontSizer" id="font">Test</p>发布于 2016-09-26 01:04:05
您可以在body onload事件上引发该事件。
<body onload="init()">
<p id="font">Test</p>
</body>这将调用您的函数,如果您放置它,但一个很好的方法,它传递给一个中间函数,在那里您调用所有这类函数(如果您有几个):
function init() {
fontSizer();
//other method to call during the body loading
}如果您愿意,我可以针对您的代码进行以下优化:
function fontSizer() {
var element = document.getElementById("font");
if (element.style.fontSize == "15px") {
elemeny.style.fontSize = "10px";
return;
}
element.style.fontSize = "15px"
}您还可以通过使用以下内容来使用css动画:
#font {
font-size: 15px;
-webkit-animation: theanim 4s;
-moz-animation: theanim 4s;
-o-animation: theanim 4s;
animation: theanim 4s;
}
@keyframes theanim {
from { font-size:10px; }
to { font-size:15px; }
}发布于 2016-09-26 01:02:54
文本效果可以通过使用带有<body onload="fontSizer()>标签的onload事件来实现。
function fontSizer() {
if (!document.getElementById("font").style.fontSize) {
document.getElementById("font").style.fontSize = "15px";
}
if (document.getElementById("font").style.fontSize == "15px") {
document.getElementById("font").style.fontSize = "30px";
} else {
document.getElementById("font").style.fontSize = "15px"
}
}<body onload="fontSizer()">
<p id="font">Test</p>
</body>
发布于 2016-09-26 02:12:12
你可以不使用javascript函数,只使用css动画:
#font {
font-size: 15px;
-webkit-animation: theanim 4s;
-moz-animation: theanim 4s;
-o-animation: theanim 4s;
animation: theanim 4s;
}
@keyframes theanim {
from { font-size:10px; }
to { font-size:15px; }
}https://stackoverflow.com/questions/39689072
复制相似问题