Если вы не знаете, насколько глубоко ваш ярлык находится в иерархии, в SwingUtilities
есть некоторые удобные функции: SwingUtilities.getAncestorOfClass (класс, компонент)
Альтернативой проверке имени родительского контейнера в ваших ярлыках может быть просто переслать событие в родительский контейнер и позволить родителям выполнить эту работу. В зависимости от того, что вы пытаетесь достичь, было бы полезно отделить этикетки от родителей. События пересылки могут быть выполнены с использованием Component. [D1] processEvent (AWTEvent)
.
В то время как ответ Tats_innit имеет приятный штрих к нему, мне пришлось сделать это немного по-другому, так как у меня на странице более одного индикатора выполнения.
вот мое решение:
JSfiddle: http://jsfiddle.net/vacNJ/
HTML (пример):
<div class="progress progress-success">
<div class="bar" style="float: left; width: 0%; " data-percentage="60"></div>
</div>
<div class="progress progress-success">
<div class="bar" style="float: left; width: 0%; " data-percentage="50"></div>
</div>
<div class="progress progress-success">
<div class="bar" style="float: left; width: 0%; " data-percentage="40"></div>
</div>
JavaScript:
setTimeout(function(){
$('.progress .bar').each(function() {
var me = $(this);
var perc = me.attr("data-percentage");
var current_perc = 0;
var progress = setInterval(function() {
if (current_perc>=perc) {
clearInterval(progress);
} else {
current_perc +=1;
me.css('width', (current_perc)+'%');
}
me.text((current_perc)+'%');
}, 50);
});
},300);
@Tats_innit: Использование setInterval () для динамического повторения прогресса - это приятное решение, thx mate! ;)
EDIT:
Мой друг написал хороший плагин jquery для пользовательских твитовских бутстрапов. Вот демо: http://minddust.github.com/bootstrap-progressbar/
Вот репозиторий Github: https://github.com/minddust/ самозагрузки-прогрессбар [/ д2]
Bootstrap использует переходы CSS3, поэтому индикаторы выполнения автоматически анимируются, когда вы устанавливаете ширину .bar trough javascript / jQuery.
http://jsfiddle.net/3j5Je/ ..видеть?
Вклад в ответ эллабеоти. вы также можете использовать это динамическое процентное значение
$('.bar').css('width', function(){ return ($(this).attr('data-percentage')+'%')});
И, возможно, добавить пользовательское ослабление к вашему css
.bar {
-webkit-transition: width 2.50s ease !important;
-moz-transition: width 2.50s ease !important;
-o-transition: width 2.50s ease !important;
transition: width 2.50s ease !important;
}
Это кросс-браузерное решение только для CSS. Надеюсь, что это поможет!
.progress .progress-bar {
-moz-animation-name: animateBar;
-moz-animation-iteration-count: 1;
-moz-animation-timing-function: ease-in;
-moz-animation-duration: .4s;
-webkit-animation-name: animateBar;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: ease-in;
-webkit-animation-duration: .4s;
animation-name: animateBar;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: .4s;
}
@-moz-keyframes animateBar {
0% {-moz-transform: translateX(-100%);}
100% {-moz-transform: translateX(0);}
}
@-webkit-keyframes animateBar {
0% {-webkit-transform: translateX(-100%);}
100% {-webkit-transform: translateX(0);}
}
@keyframes animateBar {
0% {transform: translateX(-100%);}
100% {transform: translateX(0);}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<h3>Progress bar animation on load</h3>
<div class="progress">
<div class="progress-bar progress-bar-success" style="width: 75%;"></div>
</div>
</div>
EDIT
bar
на progress-bar
в v3.1.1 HTML
<div class="container">
<div class="progress progress-striped active">
<div class="bar" style="width: 0%;"></div>
</div>
</div>
CSS
@import url('http://twitter.github.com/bootstrap/assets/css/bootstrap.css');
.container {
margin-top: 30px;
width: 400px;
}
jQuery, используемый в скрипте ниже и на document.ready
$(document).ready(function(){
var progress = setInterval(function() {
var $bar = $('.bar');
if ($bar.width()>=400) {
clearInterval(progress);
$('.progress').removeClass('active');
} else {
$bar.width($bar.width()+40);
}
$bar.text($bar.width()/4 + "%");
}, 800);
});
Демо
:)
– Tats_innit
2 December 2014 в 23:28