On the page there is a block with fixed positioning. Offset on the left edge of the screen by -100% : you need to after loading the page, after 500ms its positioning becomes left: 0% , with a speed of 500ms . and then after 5s assumed its original position. Using class assignment, I know how to do it. But I need to rewrite the left property. I tried this, but the experience is not enough:

 $('.messages')(function ($) { var left = -2000; $('.messages').css('left', left); )}; 
 .messages { display: block; position: fixed; z-index: 150; top: 40px; max-width: 600px; left: 00%; background: #97E253; padding: 5px 8px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <div class="messages">Сообщение </div> 

  • $('.messages').stop().animate({left: 0}, 500); + setTimeout(имя_функции, 500) - lexxl
  • There is no time for a detailed answer. hint - api.jquery.com/delay - xaja

2 answers 2

 $(".topBlock").css("lett", "0px") 

Units of measurement forgotten. Set interval - setTimeout (), read, there’s nothing complicated

  • one
    when specifying the value of 0 units can be 0em , since 0em = 0px = 0 - Grundy

 $(document).ready(function () { var regLeftFnc = function(elem, left) { $(elem).css('left', left); }; var timeout = setTimeout(function(){ regLeftFnc('.messages', '0'); clearTimeout(timeout); timeout = setTimeout(function(){ regLeftFnc('.messages', '-100%'); clearTimeout(timeout); }, 5000); }, 500); }); 
 .messages { display: block; position: fixed; z-index: 150; top: 40px; max-width: 600px; left: -100%; background: #97E253; padding: 5px 8px; transition: 0.5s; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <div class="messages">Сообщение </div>