Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  6. <style>
  7.  
  8. #myInput {
  9. box-sizing: border-box;
  10. background-image: url('searchicon.png');
  11. background-position: 14px 12px;
  12. background-repeat: no-repeat;
  13. font-size: 16px;
  14. padding: 14px 20px 12px 45px;
  15. border: none;
  16. border-bottom: 1px solid #ddd;
  17. }
  18.  
  19. #myInput:focus {outline: 3px solid #ddd;}
  20.  
  21. .dropdown {
  22. position: relative;
  23. display: inline-block;
  24. }
  25.  
  26. .dropdown-content {
  27. position: absolute;
  28. background-color: #f6f6f6;
  29. min-width: 230px;
  30. overflow: auto;
  31. border: 1px solid #ddd;
  32. z-index: 1;
  33. }
  34.  
  35. .hidden {
  36. display: none;
  37. }
  38.  
  39. .dropdown-content a {
  40. color: black;
  41. padding: 12px 16px;
  42. text-decoration: none;
  43. display: block;
  44. }
  45.  
  46. .dropdown a:hover {background-color: #ddd;}
  47.  
  48. </style>
  49. </head>
  50. <body>
  51.  
  52.  
  53. <div class="dropdown">
  54. <div id="myDropdown" class="dropdown-content">
  55. <input type="text" placeholder="Search.." id="myInput" onfocusin="listIn()" onfocusout="listOut()" onkeyup="filterFunction()">
  56. <div class="hidden" onclick="test()">
  57. <a href="#about">About</a>
  58. <a href="#base">Base</a>
  59. <a href="#blog">Blog</a>
  60. <a href="#contact">Contact</a>
  61. <a href="#custom">Custom</a>
  62. <a href="#support">Support</a>
  63. <a href="#tools">Tools</a>
  64. </div>
  65. </div>
  66. </div>
  67.  
  68. <script>
  69.  
  70. function test(e){
  71. e = e || window.event;
  72. var target = e.target || e.srcElement,
  73. text = target.textContent || target.innerText;
  74. document.getElementById("myInput").value = text;
  75. }
  76.  
  77. function listIn() {
  78. $("#myDropdown > div").show();
  79. }
  80.  
  81. function listOut() {
  82. $("#myDropdown > div").hide();
  83. }
  84.  
  85. function filterFunction() {
  86. var input, filter, ul, li, a, i;
  87. input = document.getElementById("myInput");
  88. filter = input.value.toUpperCase();
  89. div = document.getElementById("myDropdown");
  90. a = div.getElementsByTagName("a");
  91. for (i = 0; i < a.length; i++) {
  92. txtValue = a[i].textContent || a[i].innerText;
  93. if (txtValue.toUpperCase().indexOf(filter) > -1) {
  94. a[i].style.display = "";
  95. } else {
  96. a[i].style.display = "none";
  97. }
  98. }
  99. }
  100. </script>
  101.  
  102. </body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement