Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Opóźnienie wykonania skryptu
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
Kaluza
Witam,

W jaki sposób mogę opóźnić wykonanie się tego skryptu o np. 10 sekund?
Ktoś wchodzi na strone i odrazu wyskakuje mu popup, chciałbym żeby wyskakiwał po 10 sekundach

  1. <script type="text/javascript">
  2.  
  3. var popupStatus = 0;
  4. //this code will load popup with jQuery magic!
  5. function loadPopup(){
  6. //loads popup only if it is disabled
  7. if(popupStatus==0){
  8. $("#overlay").css({
  9. "opacity": "0.7"
  10. });
  11. $("#overlay").fadeIn("slow");
  12. $("#boxpopup").fadeIn("slow");
  13. popupStatus = 1;
  14. }
  15. }
  16.  
  17. //This code will disable popup when click on x!
  18. function disablePopup(){
  19. //disables popup only if it is enabled
  20. if(popupStatus==1){
  21. $("#overlay").fadeOut("slow");
  22. $("#boxpopup").fadeOut("slow");
  23. popupStatus = 0;
  24. }
  25. }
  26.  
  27. //this code will center popup
  28. function centerPopup(){
  29. //request data for centering
  30. var windowWidth = document.documentElement.clientWidth;
  31. var windowHeight = document.documentElement.clientHeight;
  32. var popupHeight = $("#boxpopup").height();
  33. var popupWidth = $("#boxpopup").width();
  34. //centering
  35. $("#boxpopup").css({
  36. "position": "fixed",
  37. "top": windowHeight/2-popupHeight/2
  38. });
  39. //only need force for IE6
  40. $("#overlay").css({
  41. "height": windowHeight
  42. });
  43.  
  44. }
  45. //CONTROLLING EVENTS IN jQuery
  46. $(document).ready(function(){
  47. if ($.cookie("news") != 1) {
  48. //centering with css
  49. centerPopup();
  50. //load popup
  51. loadPopup();
  52. }
  53. //CLOSING POPUP
  54. //Click the x event!
  55. $("#boxpopupClose").click(function(){
  56. disablePopup();
  57. $.cookie("news", "1", { expires: 14 });
  58. });
  59. //Click out event!
  60. $("#overlay").click(function(){
  61. disablePopup();
  62. $.cookie("news", "1", { expires: 14 });
  63. });
  64. //Press Escape event!
  65. $(document).keypress(function(e){
  66. if(e.keyCode==27 && popupStatus==1){
  67. disablePopup();
  68. $.cookie("news", "1", { expires: 14 });
  69. }
  70. });
  71. });
  72. </script>
erix
Wrzuć kod ograniczony warunkiem w:
[JAVASCRIPT] pobierz, plaintext
  1. if ($.cookie("news") != 1) {
[JAVASCRIPT] pobierz, plaintext

Do setTimeout.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.