javascript - How to control the movement of search box while searching any element in it? -
i have made search box , whenever search element in it, search box moves towards right reasons. here fiddle it.
i want make sure, whenever searching element, box should not move
(not going towards right or left).
the html, css , js have used form are:
function myfunction() { var input, filter, ul, li, a, i; input = document.getelementbyid("myinput"); filter = input.value.touppercase(); ul = document.getelementbyid("myul"); li = ul.getelementsbytagname("li"); (i = 0; < li.length; i++) { = li[i].getelementsbytagname("a")[0]; if (a.innerhtml.touppercase().indexof(filter) > -1) { li[i].style.display = ""; } else { li[i].style.display = "none"; } } }
/* search box start */ #myinput { background-image: url(../assets/img/uploads/searchicon.png); background-position: 99% 50%; background-repeat: no-repeat; font-size: 16px; margin-top: 100px; width: 670px; margin-right: auto; display: block; margin-left: auto; padding: 12px 20px 12px 40px; border: 1px solid #ddd; margin-bottom: 12px; } /* search box finish */ /* search box dropdown start */ #myul { list-style-type: none; padding: 0; width: 670px; margin-bottom: 200px; margin-left: auto; margin-right: auto; } #myul li { border: 1px solid #ddd; margin-top: -1px; /* prevent double borders */ background-color: #f6f6f6; padding: 12px; text-decoration: none; font-size: 18px; color: black; display: block } #myul li a.header { background-color: #e2e2e2; cursor: default; } #myul li a:hover:not(.header) { background-color: #eee; }
<input type="text" id="myinput" onkeyup="myfunction()" placeholder="search.." title="type in name"> <ul id="myul"> <li><a href="#" class="header">a</a></li> <li><a href="#">b</a></li> <li><a href="#">c</a></li> <li><a href="#" class="header">d</a></li> <li><a href="#">e</a></li> <li><a href="#">f</a></li> <li><a href="#" class="header">g</a></li> <li><a href="#">h</a></li> <li><a href="#">i</a></li> <li><a href="#">j</a></li> </ul>
it's caused because of elements overflow screen's height causing scrollbar appear, if want have "fullscreen", can work way around css:
body {overflow: hidden;}
or have less results showing when in initial state.
Comments
Post a Comment