Advertisement
afsarwebdev

Full Page Search Box

Sep 29th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. HTML:
  2. <ul class="nav navbar-nav navbar-right">
  3. <li><a href="#search">Search</a></li>
  4. </ul>
  5.  
  6. CSS:
  7. #search {
  8. position: fixed;
  9. top: 0px;
  10. left: 0px;
  11. width: 100%;
  12. height: 100%;
  13. background-color: rgba(0, 0, 0, 0.7);
  14.  
  15. -webkit-transition: all 0.5s ease-in-out;
  16. -moz-transition: all 0.5s ease-in-out;
  17. -o-transition: all 0.5s ease-in-out;
  18. -ms-transition: all 0.5s ease-in-out;
  19. transition: all 0.5s ease-in-out;
  20.  
  21. -webkit-transform: translate(0px, -100%) scale(0, 0);
  22. -moz-transform: translate(0px, -100%) scale(0, 0);
  23. -o-transform: translate(0px, -100%) scale(0, 0);
  24. -ms-transform: translate(0px, -100%) scale(0, 0);
  25. transform: translate(0px, -100%) scale(0, 0);
  26.  
  27. opacity: 0;
  28. }
  29.  
  30. #search.open {
  31. -webkit-transform: translate(0px, 0px) scale(1, 1);
  32. -moz-transform: translate(0px, 0px) scale(1, 1);
  33. -o-transform: translate(0px, 0px) scale(1, 1);
  34. -ms-transform: translate(0px, 0px) scale(1, 1);
  35. transform: translate(0px, 0px) scale(1, 1);
  36. opacity: 1;
  37. }
  38.  
  39. #search input[type="search"] {
  40. position: absolute;
  41. top: 50%;
  42. width: 100%;
  43. color: rgb(255, 255, 255);
  44. background: rgba(0, 0, 0, 0);
  45. font-size: 60px;
  46. font-weight: 300;
  47. text-align: center;
  48. border: 0px;
  49. margin: 0px auto;
  50. margin-top: -51px;
  51. padding-left: 30px;
  52. padding-right: 30px;
  53. outline: none;
  54. }
  55. #search .btn {
  56. position: absolute;
  57. top: 50%;
  58. left: 50%;
  59. margin-top: 61px;
  60. margin-left: -45px;
  61. background-color: limegreen;
  62. border: black;
  63.  
  64. }
  65. #search .close {
  66. position: fixed;
  67. top: 15px;
  68. right: 15px;
  69. color: #fff;
  70. background-color: limegreen;
  71. border-color: green;
  72. opacity: 1;
  73. padding: 10px 17px;
  74. font-size: 27px;
  75. }
  76.  
  77. JS:
  78. $(function () {
  79. $('a[href="#search"]').on('click', function(event) {
  80. event.preventDefault();
  81. $('#search').addClass('open');
  82. $('#search > form > input[type="search"]').focus();
  83. });
  84.  
  85. $('#search, #search button.close').on('click keyup', function(event) {
  86. if (event.target == this || event.target.className == 'close' || event.keyCode == 27) {
  87. $(this).removeClass('open');
  88. }
  89. });
  90.  
  91. $('form').submit(function(event) {
  92. event.preventDefault();
  93. return false;
  94. })
  95. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement