简体   繁体   English

弹出时为对话框添加自定义动画

[英]Adding custom animations for dialog box when popup

I want to add effects to my dialog box as in this link . 我想效果添加到我的对话框,在这个环节

I tried several examples in other sites and SO as well, but no joy. 我在其他站点和SO上也尝试了几个示例,但没有喜悦。 My dialog box takes the whole browser width and height. 我的对话框包含整个浏览器的宽度和高度。

Here's the button i'm clicking to open the dialog box, modal HTML Code, some of the CSS styles related to Dialog Box and JS Code to open the dialog Box: 这是我单击以打开对话框的按钮,模式HTML代码,与“对话框”相关的CSS样式以及用于打开对话框的JS代码:

  // Get the modal var modal = document.getElementById('myModal'); // Get the button that opens the modal var btn = document.getElementById("myBtn"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks on the button, open the modal btn.onclick = function() { modal.style.display = "block"; } // When the user clicks on <span> (x), close the modal span.onclick = function() { modal.style.display = "none"; } 
 /* The Modal (background) */ .modal { display: none; /* Hidden by default */ position: fixed; /* Stay in place */ z-index: 1; /* Sit on top */ left: 0px; top: 0px; width: 100%; /* Full width */ height: 620px; /* Full height */ overflow: auto; /* Enable scroll if needed */ background-color: rgb(0, 0, 0); /* Fallback color */ background-color: rgba(0, 0, 0, 0.4); /* Black w/ opacity */ overflow-y: hidden; } /* Modal Content/Box */ .modal-content { background-color: #fefefe; /*margin: 15% auto; 15% from the top and centered */ padding: 20px 40px 20px 40px; border: 1px solid #888; /*width: 80%; Could be more or less, depending on screen size */ } 
 <div class="site-body"> <h1>Click the Button to Open Modal</h1> <button id="myBtn" class="modal-btn">Open Modal</button> </div> <div id="myModal" class="modal"> <!-- Modal content --> <div class="modal-content"> <span class="close">x</span> <image class="logo" src="images/logo.png" /> <div class="header"> <div class="reference"> <div class="row font-size1"> <div class="label"><strong>OR Ref:</strong> </div> <div class="value"><strong>1-2-123456789</strong> </div> </div> <div class="row font-size1"> <div class="label"><strong>CP Ref:</strong> </div> <div class="value"><strong>hID-prod123456</strong> </div> </div> </div> <div class="search"> <div class="row right-align"> <div class="left-align label show-right-margin"><strong>Note Type: </strong> </div> <select class="left-align"> <option>All Notes</option> <option>Any</option> </select> <button class="search-btn left-align">Search</button> </div> </div> </div> <div class="error">Sorry, We couldn't fetch all of the notes you asked for. Please try again or report an error if it continues to happen </div> </div> 

How to add animations to dialog box when poping up as in this link ? 像此链接一样弹出时如何在对话框中添加动画?

JQuery has a fairly strait forward method for showing/hiding elements with an animation. JQuery有一个相当棘手的前进方法,用于显示/隐藏带有动画的元素。 It isn't exactly what is in the example but fairly close and, again, very simple. 它与示例中的内容不完全相同,但非常接近,而且非常简单。

// When the user clicks on the button, open the modal 
btn.onclick = function() {
  $('.modal').show('fast');
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
  $('.modal').hide('fast');
}

You could also experiment with JQuery slideDown() and slideUp() functions (just replace show() and hide() with these two respectively). 您还可以尝试使用JQuery slideDown()slideUp()函数(只需分别用这两个替换show()hide() )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM