I am dealing with jQuery animation with infinite loop and my code is below:
var width = $(document).width() - $('#mydiv').width();
$(document).ready(function() {
function animateMydiv() {
$('#mydiv').animate({
'left': width + 'px'
}, 9000,
function() {
$('#test').css({
opacity: 1.0,
visibility: "visible"
}, 9000).animate({
opacity: 0
}, 9000);
}).animate({
'left': '0px'
}, 9000);
}
animateMydiv();
});
#mydiv {
width: 40px;
height: 40px;
position: absolute;
left: 0;
background: black;
}
#test {
visibility: hidden;
position: absolute;
left: 0;
top: 50;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="mydiv"></div>
<p id="test">
Hi welcome...!!
</p>
I used animateMydiv()
to loop infinite but it not worked.