2
我嘗試暫停/恢復文本上的過渡動畫。對於類似的問題,我嘗試了很多解決方案,但仍然沒有成功。JavaScript暫停並恢復文本上的過渡動畫
我想暫停'顏色效果',當點擊暫停按鈕,當我點擊恢復按鈕'顏色效果'將完成作業着色整個文本基於休息時間。
這是我的代碼。
$(document).ready(function(){
$('#start').on('click', function() {
$(this).text('Resume');
$(this).attr('disabled',true);
$('span').addClass('active');
$('span').dequeue();
});
$("#stop").click(function() {
$('#start').attr('disabled',false);
$('#start').clearQueue();
$("span").stop();
/*
* it similiar like below,
* but still not perfect.
* when the duration of background-position-x has finished,
* the transition start again. and yet still not perfect
*/
/*$('span').animate({
'background-position-x': '10%',
'background-position-y': '20%'
}, 10000, 'linear');*/
});
})
body {
\t \t background: #ccc;
\t }
\t span {
\t height: 25px;
\t background-size: 200% 100%;
\t background-image: linear-gradient(to right, orange 50%, white 50%), linear-gradient(to right, transparent 50%, transparent 50%);
\t text-indent: 28px;
\t font-size: 30px;
\t background-size: 200% 100%;
\t background-repeat: no-repeat;
\t background-position: 100% top, 100% top;
\t -webkit-background-clip: text, border-box;
\t background-clip: text, border-box;
\t color: transparent;
\t }
\t .active {
\t \t background-position: 0% top, 0% top;
\t transition: background-position 10s;
\t }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p><span>Lorem ipsum dolor sit amet</span></p>
<button id="start">Start</button>
<button id="stop">Pause</button>
注:我知道有這麼多「的JavaScript暫停/恢復」問題,我已經嘗試用我的情況下實現的,但還是沒有成功。
Wow excellent ..!非常感謝你......我在另一個解決方案上使用了動畫播放狀態,但不工作。現在我知道如何使用它。非常感謝。 – fandiahm