search-bar.js 542 B

123456789101112131415161718192021
  1. $.fn.searchBar = function() {
  2. var $input = this.find('input[type=search]'),
  3. $cancelBtn = this.find('a.searchbar-cancel'),
  4. $ele = this;
  5. $input.off('click.searchinput').on('click.searchinput',function() {
  6. $ele.addClass('searchbar-active');
  7. $cancelBtn.css({
  8. display: 'block',
  9. 'margin-right': 0
  10. });
  11. });
  12. $cancelBtn.off('click.searchbtn').on('click.searchbtn',function() {
  13. $ele.removeClass('searchbar-active');
  14. $cancelBtn.css({
  15. 'margin-right': (function(){
  16. return -$cancelBtn[0].offsetWidth + 'px'
  17. })()
  18. })
  19. });
  20. }