Modal Dialog con jQuery
Modal Dialog
This is a modal window. You can do the following things with it:
- Read: Modal windows will probably tell you something important so don't forget to read what it says.
- Look: modal windows enjoy a certain kind of attention; just look at it and appreciate its presence.
- Close: click on the button below to close the modal.
Codice della Lezione: Modal Dialog con jQuery
//inizializzazione jQuery
$(document).ready(function(){
$("#button1").on('click',function(){
$('.my-modal').addClass('my-show');
});
$(".my-close").click(function(){
$('.my-modal').removeClass('my-show');
});
// Esaminare la stringa e restituire un numero intero
let top = parseInt($('.md-modal').css('top'));
//seleziona la finestra del broser e con l'evento scroll abilita la funzione
$(window).scroll(function(){
//crea la variabile che sull'elemento finestra che indica la posizione verticale corrente + 100px
let corrente = $(this).scrollTop()+100;
// seleziona l'elemento a cui destinare la variabile corrente sottoforma di css (all'istruzione top)
$('.my-modal').css('top',corrente)
});
});