我正在使用纯 javascript 处理淡入和淡出功能,代码如下:
<script>
function fadeIn(el, ms) {
var opacity = 1,
interval = 50,
gap = interval / ms;
window.setInterval(function{
opacity -= gap;
el.style.opacity = opacity;
if(opacity <= 0) {
window.clearInterval(fading);
el.style.display = 'none';
}
}, interval);
}
function fadeOut(el, ms){
var opacity = 0,
interval = 50,
gap = interval / ms;
el.style.display = 'block';
el.style.opacity = opacity;
window.setInterval(function{
opacity += gap;
el.style.opacity = opacity;
if(opacity >= 1) {
window.clearInterval(fading);
}
}, interval);
}
</script>
在正文部分,代码是:
<input type="button" onclick="fadeOut(this, 50);" value="hi" />
页面加载时立即给出错误“错误意外令牌(”:
window.setInterval(function{
当我尝试单击输入按钮时,出现错误:“找不到变量fadeIn”