加載中三個點點動態出現

js定時器方法javascript

//html
<div>加載中<span id="dot"></span></div>

//js
<script>
 let dotting = function () {
        let dom = document.getElementById('dot');
        let html = dom.innerHTML;
        if(html.length >= 3){
            dom.innerHTML = ''
        } else {
            dom.innerHTML = html + '.'
        }
    }
    setInterval(dotting, 800)

</script>

 

方法都來自於網上其餘博客  css

css3 anminate方法  html

方法1:java

//html
<div>加載中<span id="dot">...</span></div>

//css
<style>  
#dot {
    display: inline-block;
    width: 1.5em;
    vertical-align: bottom;
    overflow: hidden;
    animation: dotting 3s infinite step-start;
}
@keyframes dotting{
    0% { width: 0; margin-right: 1.5em; }
    33% { width: .5em; margin-right: 1em; }
    66% { width: 1em; margin-right: .5em; }
    100% { width: 1.5em; margin-right: 0;}
}
</style>

  

方法2:  這個方法的好處是能夠方便的設置大小css3

//html
<div>加載中<span id="dot"></span></div>
//css
<style>
#dot{
    height: 4px;
    width: 4px;
    display: inline-block;
    border-radius: 2px;
    animation: dotting 2.4s  infinite step-start;
}
@keyframes dotting {
    25%{
        box-shadow: 4px 0 0 #000;
    }
    50%{
        box-shadow: 4px 0 0 #000000 ,14px 0 0 #000;
    }
    75%{
        box-shadow: 4px 0 0 #000 ,14px 0 0 #000, 24px 0 0 #000;
    }
}
</style>

  

還有其餘不少種方法啦,效果出來就行 dom

相關文章
相關標籤/搜索