html code
<div class="popup"> <div class="popup__bg"></div> <div class="form"> <form class='popupform'> <input type="text" placeholder="ΠΠ°ΡΠ΅ ΠΈΠΌΡ" required> <input type="text" placeholder="ΠΠ°Ρ Π½ΠΎΠΌΠ΅Ρ ΡΠ΅Π»Π΅ΡΠΎΠ½Π°" required> <textarea placeholder='ΠΠΏΠΈΡΠ°Π½ΠΈΠ΅' required></textarea> <input type="submit" calue="ΠΡΠΏΡΠ°Π²ΠΈΡΡ"> </form> <div class="popup__close">x</div> </div> </div>
css code:
.popup { position: absolute; height:100%; width:100%; top:0; left:0; display:none; } .popup__bg { background:rgba(0,0,0,0.6); position:absolute; z-index:1; height:100%; width:100%; } .form { position: relative; margin:10% auto; z-index:2; width: 30%; padding: 2%; background: rgb(94, 70, 96); background: rgba(101, 70, 96, 0.8); border:1px solid rgb(94, 70, 96); border-radius:20px; box-shadow:0 0 2px rgba(0,0,0,0.5); } .popupform { text-align: center; } .popupform input, .popupform textarea{ padding: 1% 2%; width: 85%; display: inline-block; margin-top: 1em; outline: none; border-radius: 10px; font-size: 1.25rem; } .popupform input[type='submit'] { width: 50%; transition: all 0.1s linear 0.2s; border: none; } .popupform input[type='submit']:hover { background: green; color: #ffffff; } .popup__close { width: 5%; position: absolute; top: 3%; right: 2%; border: 2px solid #000; border-radius: 20px; text-align: center; vertical-align: middle; background: rgb(137, 0, 152); background: rgba (137, 0, 152, 0.7); cursor: pointer; transition: all 0.1s linear 0.1s; color: white; font-size: 1.25rem; } .popup__close:hover { background: red; color: #000; border: 2px solid #fff; }
js code:
$(document).ready(function() { $(".popup__bg").click(function(){ $(".popup").fadeOut(800); }); $(".popup__close").click(function(){ $(".popup").fadeOut(800); }); }); function showPopup() { $(".popup").fadeIn(800); }
In the html-code there are several buttons with a pop-up window (at the beginning and in the middle of the page), the drop-down of the window is defined by positioning.Can you somehow tie the window to the button that calls it (so that the window appears next to the button, and not according to the positioning coordinates)?Is it possible that when clicking on a specific button, the text of the placeholders of the form changes?
var coordinates = $('#button').offset()
$('.popup').offset(coordinates)
var popup = $('.popup'); $('.button').click(function(e) { var coordinates = $(this).offset(); //ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΠΊΠ»ΠΈΠΊΠ½ΡΡΠΎΠΉ ΠΊΠ½ΠΎΠΏΠΊΠΈ coordinates.top += $(this).height() / 2; // ΠΠ° Π²ΡΡΠΎΡΠ΅ ΡΠ΅ΡΠ΅Π΄ΠΈΠ½Ρ ΠΊΠ½ΠΎΠΏΠΊΠΈ coordinates.left += $(this).width() + 15; //ΠΡΠΎΠ΄Π²ΠΈΠ³Π°Π΅ΠΌ ΠΎΡ ΠΊΠ½ΠΎΠΏΠΊΠΈ Π½Π° 15 ΠΏΠΈΠΊΡΠ΅Π»Π΅ΠΉ popup.offset(coordinates); //Π£ΡΡΠ°Π½Π°Π²Π»ΠΈΠ²Π°Π΅ΠΌ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΠΏΠΎΠΏΠ°ΠΏΡ popup.fadeIn(800); });
.popup { display: none; width: 100px; height: 100px; background-color: gray; z-index: 999; } p { margin-bottom: 100px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="popup"></div> <div id="demo"> <p> <button class="button">Click me!</button> </p> <p> <a href="#" class="button">Click me too!</a> </p> </div>
Source: https://ru.stackoverflow.com/questions/520350/More articles:What is the principle behind the construction of a complex LEFT JOIN in PostgreSQL?Does the class have multiple responsibilities if it contains one public method?How to assign a class to a parent unit if a radio button is selected inside it?Windows 10 installer does not see the βsewnβ keyProgress bar in infinite ListViewhow to output an array in a loopHow to test the model?The program is not removed from the new window βApplications and Featuresβ windows 10PHP Version 5.3.10-1ubuntu3.152021 in datepickerAll Articles