【问题标题】:Fill image in a div from center将图像从中心填充到 div 中
【发布时间】:2019-10-23 02:06:37
【问题描述】:

在整个页面加载时;黄色圆圈需要从距离中心的 1 条细线开始,并将“形成/填充”整个圆圈。

我使用了 jPreloader。我不确定如何从中心开始加载徽标。目前,高度随着页面加载而动画化。

将高度分配给 div 的 Javascript。

$(jBar).stop().animate({
        height: per + '%'
    }, 500, 'linear');

标志所在的CSS:

#jpreBar {
     border-radius:0%;
     -moz-border-radius:0%;
     -webkit-border-radius:0%;

     background: url(../images/logo.jpg) left top no-repeat;

     animation: progress 2s linear infinite;
     -moz-animation: progress 2s linear infinite;
     -webkit-animation: progress 2s linear infinite;
     -ms-animation: progress 2s linear infinite;
     -o-animation: progress 2s linear infinite; 
}

动画需要是这样的,从左到右:

【问题讨论】:

  • 你能不能只使用center center而不是left top来定位你的图像?
  • 这会使徽标也移动,请检查链接。标志是从上到下的,它更好,但仍然不像客户想要的那样。
  • 只是一些建议,你应该声明 -webkit-,-moz-,-ms- 和 -o-animation 以及不带前缀的动画,顺序很重要!

标签: javascript jquery html css jpreloader


【解决方案1】:

从我的jsFiddle 试试这个代码。认为这将对您有所帮助并将功能添加到您的加载屏幕。 动画时间和边框都是我自己加的来测试的。

HTML:

<div id="outer">
    <div id="jpreBar"></div>
</div>

<input id="input" value="0" />
<button id="button">Update</button>

JS

$(document).ready(function(){
   $('#button').click(function(){
      var per = $('#input').val();

      var height = per;
      backgroundy = -176 + 176 * (per/100);
      margintop = 176 - 176 * (per/100);

      $('#jpreBar').stop().animate({
         'height': height + '%',
         'background-position-y': backgroundy + 'px',
         'margin-top': margintop + 'px'
      }, 5000, 'linear');
   });  
});

CSS

#jpreBar {
 border-radius:0%;
 -moz-border-radius:0%;
 -webkit-border-radius:0%;

 background-image: url("http://50.87.144.37/~projtest/team/design/yellowmedia/images/logo.jpg");
 background-repeat: no-repeat;
 background-position: 0px -176px;
 height: 0%;
 margin-top: 176px;

 animation: progress 2s linear infinite;
 -moz-animation: progress 2s linear infinite;
 -webkit-animation: progress 2s linear infinite;
 -ms-animation: progress 2s linear infinite;
 -o-animation: progress 2s linear infinite; 

 border: 0px solid black;
}

#outer{
 border: 0px solid black;
 height: 351px;
}

【讨论】:

  • 我在预加载的上下文中使用了这个标志。徽标将与加载的页面数量相关,因此我无法给出静态动画时间段。
  • 好吧,你是对的,所以我更新了我的 js - look at here
猜你喜欢
  • 1970-01-01
  • 2011-05-18
  • 1970-01-01
  • 1970-01-01
  • 2014-01-07
  • 1970-01-01
  • 1970-01-01
  • 2019-11-06
  • 2017-12-06
相关资源
最近更新 更多