Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript]Uruchomienie modal-a po załadowaniu strony
Forum PHP.pl > Forum > Przedszkole
krzesik
Witam, pytanie trywialne , ale sam już nie wiem gdzie robię błąd
mam modala
  1. <button id="myBtn">Open Modal</button>
  2.  
  3. <!-- The Modal -->
  4. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  5.  
  6. <!-- Modal content -->
  7. <div class="modal-content">
  8. <div class="modal-header">
  9. <span class="close">&times;</span>
  10. <h2>Tilte</h2>
  11. </div>
  12. <div class="modal-body">
  13. <p>Some text in the Modal Body</p>
  14. <p>Some other text...</p>
  15. </div>
  16. <div class="modal-footer">
  17. <h3>Footer</h3>
  18. </div>
  19. </div>
  20.  
  21. </div>


później scripty
  1. <script type="text/javascript">
  2. // Get the modal
  3. var modal = document.getElementById('myModal');
  4.  
  5. // Get the button that opens the modal
  6. var btn = document.getElementById("myBtn");
  7.  
  8. // Get the <span> element that closes the modal
  9. var span = document.getElementsByClassName("close")[0];
  10.  
  11. // When the user clicks the button, open the modal
  12. btn.onclick = function() {
  13. modal.style.display = "block";
  14. }
  15.  
  16. // When the user clicks on <span> (x), close the modal
  17. span.onclick = function() {
  18. modal.style.display = "none";
  19. }
  20.  
  21. // When the user clicks anywhere outside of the modal, close it
  22. //window.onclick = function(event) {
  23. // if (event.target == modal) {
  24. // modal.style.display = "none";
  25. // }
  26. // }

uruchamia się po wciśnięciu przycisku, ale jak zrobić aby uruchamia się po załadowaniu strony
zamiast powyższego dawałem:
  1. <script type="text/javascript">
  2. $(document).ready( function(){
  3. $('#myBtn').modal('show');
  4. });
  5.  


ale bez efektu..
nospor
#myBtn to przeciez button... Jak chcesz pokazac modal to masz zrobic modal na div a nie na button
krzesik
ok, poprawiłem, ale dalej brak zamierzonego efektu

po korekcie mam tak:
<script type="text/javascript">
$(document).ready( function(){
$('#myModal').modal('show');
});

</script>
nospor
wg kodu z pierwszego posta nie uzywasz pluginu modal, tylko recznie pokazujesz kod.

Wiec nie:
$('#myModal').modal('show');
a:
$('#myModal').show();

Zakladam ze chociaz jQuery masz zaladowane wink.gif
krzesik
:-) teraz jest git
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.