Created
March 30, 2012 02:04
-
-
Save beakr/2245767 to your computer and use it in GitHub Desktop.
Nice search bar (hand made).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.search { | |
/* Roundness */ | |
border: 1px solid #BABABA; | |
border-radius: 20px; | |
height: 35px; | |
width: 300px; | |
padding: 8px; | |
background: white; | |
/* Fonts and text */ | |
font-family: "Helvetica Neue", sans-serif; | |
font-weight: 500; | |
font-size: 20px; | |
color: #7A7A7A; | |
box-shadow: 1px 5px 2px #EDEDED; | |
} | |
.search:hover { | |
background: #FCFCFC; | |
} | |
.search:focus { | |
outline: none; | |
background: #FFFFFF; | |
border-color: #7AB0E6; | |
} | |
#mglass {margin-left: 5px;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link href="search_bar.css" rel="stylesheet" type="text/css" media="all"> | |
<script src="jquery.min.js" type="text/javascript"></script> | |
<script src="search.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<!-- Search icon by iconic icon pack (http://somerandomdude.com/work/iconic/) --> | |
<input class="search" type="text" value="Search..."><img id="mglass" src="search.png"> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
// Auto-selection when clicked | |
$(".search").click(function() { | |
$(this).select(); | |
$(".search").css('color', 'black'); | |
}); | |
// Text turns gray again when not typing | |
$(".search").blur(function() { | |
$(".search").css('color', '#7A7A7A'); | |
}); | |
// Expand search bar | |
$(".search").focus(function() { | |
$(this).animate({ width: "300px" }, 250); | |
}); | |
$(".search").blur(function() { | |
$(this).animate({ width: "150px" }, 200); | |
}); | |
// Search... dissapears when field is clicked | |
$('.search').focus(function() { | |
if ($(this).val() === 'Search...') { | |
return $(this).val(''); | |
} | |
}); | |
// Search... reappears when field is not in focus anymore | |
$('.search').blur(function() { | |
if ($(this).val() === '') { | |
return $(this).val('Search...'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment