[英]How To Make A Loading Screen with Material Framework?
I am pretty sure there are many articles on this. 我很确定有很多关于此的文章。 In fact, I have seen many that I have used before.
事实上,我见过很多我以前用过的东西。 The thing is, I am using Material Design by Google.
问题是,我正在使用Google的Material Design。 So they have loading elements already in the framework.
所以他们已经在框架中加载了元素。 It looks something like this:
它看起来像这样:
<div class="mdl-spinner mdl-spinner--single-color mdl-js-spinner is-active"></div>
Previously I have had trouble with this kinda thing. 以前我遇到过这种事情的麻烦。 If someone could help me out, that would be great.
如果有人可以帮助我,那就太好了。
Here is the link to what the loading animation looks like: https://getmdl.io/components/index.html#loading-section (it is the spinner). 这是加载动画的外观链接: https : //getmdl.io/components/index.html#loading-section (它是微调器)。
MDL just provides the spinner and it's up to the developer to integrate it into the page for what ever your need's may be. MDL只提供微调器 ,由开发人员将其集成到页面中,以满足您的需求。 In this case you want to use it on page load.
在这种情况下,您希望在页面加载时使用它。
To create a loading spinner you first need to place a <div class="mdl-spinner mdl-js-spinner is-active">
at the top of your document. 要创建加载微调器,首先需要在文档顶部放置一个
<div class="mdl-spinner mdl-js-spinner is-active">
。 I suggest right above the closing </head>
tag. 我建议在结束
</head>
标记之上。
To center the spinner you can do it with flex box like so. 要使微调器居中,您可以使用柔性盒这样做。 Place the spinner inside a container above the closing
</head>
将微调器放在关闭
</head>
上方的容器内
<div class="spinner">
<div class="mdl-spinner mdl-js-spinner is-active"></div>
</div>
Centering the spinner with flexbox. 使用flexbox将微调器对中。 The
spinner
is set to display:none
to hide it from view atm . spinner
设置为display:none
以将其从视图atm中隐藏。 Adding a class of spinner-on
and giving it the display
property of flex
that we trigger on with jQuery when we want to show it. 添加一个
spinner-on
类,并在我们想要显示它时为它提供我们使用jQuery触发的flex
的display
属性。
$spinner-size:100px;
html, body, .spinner{
height:100%;
overflow: hidden;
}
.mdl-spinner{
height:$spinner-size;
width:$spinner-size;
}
.spinner{
position:relative;
display: none;
align-items: center;
justify-content: center;
}
.spinner-on {
display: flex;
}
With jQuery we trigger our spinner-on
class which brings spinner into view. 使用jQuery,我们触发了我们的
spinner-on
类,它将spinner带入视图。 Then we use fading functions to fade in the spinner and fade it out after a set amount of time. 然后我们使用淡入淡出函数淡入微调器并在一段时间后将其淡出。 Overflow is also set se we can now scroll the page.
现在我们可以滚动页面来设置溢出。
$(function() {
var overflow = $('body,html, .spinner');
$(".spinner").addClass('spinner-on');
$(".spinner").fadeOut(2000, function() {
$("body").fadeIn(2000);
overflow.css('overflow','visible');
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.