首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用css创建加载器

使用css创建加载器
EN

Stack Overflow用户
提问于 2018-07-24 01:43:27
回答 1查看 214关注 0票数 1

我正在尝试创建一个加载器为我的网站使用css和javascript,它必须看起来像

到目前为止,我可以创建滑块,但我无法将框放在滑块后面。我该怎么办呢。

编辑-抱歉,如果不清楚,但我想要的橙色滑块作为一个动画加载器

HTML -

 <div style="margin-left:400px; margin-right:400px " class="progress-wrap 
 progress" data-progress-percent="20">
   <div class="progress-bar progress"></div>
 </div>

CSS -

@import "compass/css3";
.red{
    background:black;
  margin-left:300px;
  top:100px;

}
.box{
    width:100px !important;
    height:100px !important;
  z-index:-1;

}
.progress {
  width: 100%;
  height: 10px;
}
.progress-wrap {
  background: #f80;
  margin: 200px 0;
  overflow: hidden;
  position: relative;
  .progress-bar {
    background: white;
    left: 0;
    position: absolute;
    top: 0;
  }
}

Javascript-

moveProgressBar();
$(window).load(function() {
    moveProgressBar();
});

function moveProgressBar() {
  console.log("moveProgressBar");
    var getPercent = ($('.progress-wrap').data('progress-percent') / 100);
    var getProgressWrapWidth = $('.progress-wrap').width();
    var progressTotal = getPercent * getProgressWrapWidth;
    var animationLength = 6500;


    $('.progress-bar').stop().animate({
        left: progressTotal
    }, animationLength);
}
EN

回答 1

Stack Overflow用户

发布于 2018-07-24 04:32:28

对于动画,您可以使用setInterval以每200毫秒增加一次进度条的width

.main{
 float: right;
}
.box{
  position: relative;
}
.bar{
  position: absolute;
  top: 105px;
  right: 111px;
  width: 100%;
  border: 1px solid black;
}
.left{
  width: 143px;
  height: 143px;
  background: #595d59;
  display: inline-block;
  margin-right: -2px;
  }
  
  .right{
  width: 143px;
  height: 143px;
  background: #b8b9b8;
  display: inline-block;
  margin-left: -2px;
  }
  
  .progress-bar{
  width: 5%;
  height: 11px;
  background: #f26522;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="ru" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
 <div class="main" > 
   <div class="box">
     <div class ="left"></div>
     <div class ="right"></div>
   </div>
   <div class="bar">
     <div class="progress-bar"></div>
   </div>
   
 </div>
 <script>
var width = 5;
var progress;
progress=	setInterval(function(){
  	$('.progress-bar').css("width", width + "%");
    width += 5;
    if(width>=105){
    	clearInterval(progress);
    }
  }, 200);
    
</script>

</body>
</html>

JSFiddle:http://jsfiddle.net/21jdo8q7/1/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51484508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档