I am currently working on a set of code that runs every time a certain ajax call occurs.
For this, I use the snippet below (these are errors, since I think there is no html or css, but this is normal, as I am just trying to show my code):
$(document).ajaxStart(function() {
if ($('.spinner').length < 1) {
$('body').prepend('<div class="spinner" title="Spinner stuck? Click to remove!"></div>');
}
$('body div').not('.spinner').css('opacity', '0.5');
});
.done(function(xhr) {
$('body div').not('.spinner').css('opacity', '0');
$('body').one('transitionend', function(e) {
$('body div').not('.spinner').remove();
$('body').append(xhr);
$('body div').not('.spinner').css('opacity', '0.1');
$('body').one('transitionend', function(e) {
$('body div').css('opacity', '1');
$('.spinner').remove();
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
Run codeHide result, .one('transitionend') s, , ( : ajax. ajax, ajax - , $('body div').not('.spinner').css('opacity', '0.1');, ).
jsfiddle. .
( ), , ( , - , ), , log - $('#log span').text($('#div1').text()); ..).
, jsfiddle :
var newCss = {
backgroundColor: 'blue',
width: '25%',
color: 'white'
};
var disabled = false;
$(document).on('click', '#div1', function(e) {
if (disabled) return;
notNested($(this));
});
$(document).on('click', '#div8', function(e) {
if (disabled) return;
nested($(this));
});
function notNested($this) {
disabled = true;
$this.css(newCss);
$('#log span').text($('#div1').text());
$('#div1').one('transitionend', function() {
$('#div2').css(newCss);
$('#log span').text($('#div2').text());
});
$('#div2').one('transitionend', function() {
$('#div3').css(newCss);
$('#log span').text($('#div3').text());
});
$('#div3').one('transitionend', function() {
$('#div4').css(newCss);
$('#log span').text($('#div4').text());
});
$('#div4').one('transitionend', function() {
$('#div5').css(newCss);
$('#log span').text($('#div5').text());
});
$('#div5').one('transitionend', function() {
$('#div6').css(newCss);
$('#log span').text($('#div6').text());
});
$('#div6').one('transitionend', function() {
$('#div7').css(newCss);
$('#log span').text($('#div7').text());
});
$('#div7').one('transitionend', function() {
$('div').removeAttr('style');
$('#log span').text('');
disabled = false;
});
}
function nested($this) {
disabled = true;
$this.css(newCss);
$('#log span').text($('#div8').text());
$('#div8').one('transitionend', function() {
$('#div9').css(newCss);
$('#log span').text($('#div9').text());
$('#div9').one('transitionend', function() {
$('#div10').css(newCss);
$('#log span').text($('#div10').text());
$('#div10').one('transitionend', function() {
$('#div11').css(newCss);
$('#log span').text($('#div11').text());
$('#div11').one('transitionend', function() {
$('#div12').css(newCss);
$('#log span').text($('#div12').text());
$('#div12').one('transitionend', function() {
$('#div13').css(newCss);
$('#log span').text($('#div13').text());
$('#div13').one('transitionend', function() {
$('#div14').css(newCss);
$('#log span').text($('#div14').text());
$('#div14').one('transitionend', function() {
$('#log span').text('');
$('div').removeAttr('style');
disabled = false;
});
});
});
});
});
});
});
}
body {
display: flex;
align-items: flex-start;
}
div {
display: inline-block;
width: 25%;
}
div > div {
border: 4px dotted red;
transition: .25s;
display: block;
width: 10%;
padding: 4px 8px;
margin: 16px 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div>
<div id="div1">1</div>
<div id="div2">2</div>
<div id="div3">3</div>
<div id="div4">4</div>
<div id="div5">5</div>
<div id="div6">6</div>
<div id="div7">7</div>
</div>
<div id="log">We got to: <span></span>
</div>
<div>
<div id="div8">8</div>
<div id="div9">9</div>
<div id="div10">10</div>
<div id="div11">11</div>
<div id="div12">12</div>
<div id="div13">13</div>
<div id="div14">14</div>
</div>
Hide result, , ? /? .. , ( , ), ? ( , , TUVM)
jQuery . queue . delay, (, ). , ? , setTimeout() - , , ( .one('transitionend'), , , ...)
UPDATE:
, :
, css Jquery, / . , DOM . - Jan_dh
jsfiddle, , , CSS. - ( jsfiddle ).
, :
, DOM .
, , -, , , ?