Thursday, November 1, 2012

Kotak Penelusuran dalam Simbol

Kotak Penelusuran dalam Simbol

Menciptakan elemen kotak penelusuran tersembunyi dengan jQuery. Saat keadaan normal, kotak penelusuran akan tampak sebagai ikon kaca pembesar, dan saat ikon tersebut diklik, itu akan memicu kotak penelusuran di dalamnya untuk tampil:

HTML

<form class="search-form" action="/search" method="get">
    <div class="input-wrapper">
        <input type="text" name="q" placeholder="Search...">
        <a title="Search" class="sc" href="/"></a>
    </div>
</form>

CSS

.input-wrapper {
  border:1px solid #B9E8FB;
  width:26px;
  height:26px;
  background-color:white;
  -webkit-box-shadow:inset 0 1px 1px rgba(0,0,0,.2);
  -moz-box-shadow:inset 0 1px 1px rgba(0,0,0,.2);
  box-shadow:inset 0 1px 1px rgba(0,0,0,.2);
  -webkit-border-radius:30px;
  -moz-border-radius:30px;
  border-radius:30px;
  overflow:hidden;
  position:relative;
}

.input-wrapper input,
.input-wrapper input:focus {
  border:none;
  background:none;
  margin:0 0;
  padding:0 16px;
  display:block;
  width:200px;
  height:26px;
  font:italic bold 12px/26px Arial,Sans-Serif;
  color:#1C86AF;
  outline:none;
}

.input-wrapper.focus {
  background-color:#EAF7FC;
  border-color:#3EBFF0;
}

.input-wrapper .sc {
  display:block;
  position:absolute;
  top:0;
  right:0;
  bottom:0;
  left:0;
  background:white url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAGOSURBVDhPrZJPSwJRFMXPokD6BkFQyzaRQUGrKII21a5Vu9oHLVq07hNUSFSYWqOmwjSGY0aRQqsCXUQJlaXSaEZamI2mTnV7WguNMUR6cHiX98793fv+AP8+9gvd2P9cYuKZdPDQYH01/NSMPcWCYyIcVMjL4r13AT7S/A1yFZzM+J3sUZYZbByisojDEuCD4C4GGKRJHbIjj+DoxyjI2iqTmGuHq/AIt0JwFgdqAF4dcOUJvDynanDK8xCLBCHjrQF48WE3S9h+61A18C/97DiEnXRaHWBPiuDTBHtqQtXgSE1BkAm2pF8dYHuYheOJYE3kVQ3WRACOVGl/uvZLmOMxWO4JW9IFzLExcNFWcNIouNgJrGzdHCup+oKraJzUBlM4DovE7iJB5YqlmbsjbEYfsBXJwp5k8U1v7S6MEQ2MoRnob5/L3RhvMzCEFrDmb4H+ugebkSI2Qp8w3HTV9zt/u0yhIQbMwRjOw3De1xhkNTiM9eAHTFHC2mVnYxDdqRb6KwUrZ5ONASqyvgCU5N7E8iBBBAAAAABJRU5ErkJggg==') no-repeat 50% 50%;
  -webkit-border-radius:30px;
  -moz-border-radius:30px;
  border-radius:30px;
}

jQuery

$(function() {
    $('.search-form .sc').on("click", function() {
        $(this).hide()
            .parent().addClass('focus')
                .stop().animate({width:200}, 120, "swing")
                    .find('input').trigger("focus")
                        .on("focusout", function() {
            $(this).next().show()
                .parent().removeClass('focus')
                    .stop().animate({width:26}, 120, "swing");
        });
        return false;
    });
});

Demo

Labels: , , ,

10 Comments:

At Thursday, November 1, 2012 at 12:36:00 PM GMT+7, Blogger abang ichal said...

klo yg sekali sentuh tanpa klik bmana?

 
At Thursday, November 1, 2012 at 3:09:00 PM GMT+7, Blogger Unknown said...

coba bantu :) maksudnya kaya gini ya?? http://jsfiddle.net/hadhill/wRKtc/1/

kode jquerynya ganti ini
$(function() {
$('.search-form .sc').on("hover", function() {
$(this).hide()
.parent().addClass('focus')
.stop().animate({width:200}, 120, "swing")
.find('input').trigger("focus")
.on("focusout", function() {
$(this).next().show()
.parent().removeClass('focus')
.stop().animate({width:26}, 120, "swing");
});
return false;
});
});​


mohon koreksinya lagi :)

 
At Thursday, November 1, 2012 at 10:06:00 PM GMT+7, Blogger Taufik Nurrohman said...

Meletakkan event .hover() di dalam JQuery .on() setahu Saya tidak sesuai prosedur meskipun berhasil, karena event .hover() hanyalah penggabungan antara .mouseenter() dan .mouseleave()
Jadi, cukup tuliskan begini saja:

$(function() {
$('.search-form .sc').on("mouseenter", function() {
$(this).hide()
.parent().addClass('focus')
.stop().animate({width:200}, 120, "swing")
.find('input').trigger("focus")
.on("focusout", function() {
$(this).next().show()
.parent().removeClass('focus')
.stop().animate({width:26}, 120, "swing");
});
return false;
});
});​

 
At Saturday, November 3, 2012 at 3:27:00 PM GMT+7, Blogger Unknown said...

cara masangnya gimana om? maklum masih nubi

 
At Monday, November 19, 2012 at 11:17:00 PM GMT+7, Blogger Panjz mackenzie said...

mas yang ganteng... :D
boleh tanya ga??
maaf sebelumnya saya bertanya d tempate yang salah..
kenapa iah wktu saya pasang carousel kotak pencarian saya hilang.. padahal sebelom pasang ada bahkan sukses..hehehe saya pasang kotak pencarian yang sembunyi dr mas...
apa kah ngaruh iah?? :'(

 
At Wednesday, December 19, 2012 at 8:29:00 PM GMT+7, Blogger Rohis Facebook said...

mirip sprti pencarian yg ada dlm grop FB.., bisa gk mas klo gk pake JQuery hny CSS sj.., soalx takut blog sy jd berat, makasih.. :)

 
At Thursday, December 20, 2012 at 6:31:00 PM GMT+7, Blogger Taufik Nurrohman said...

Cek salinan Saya di sini: http://codepen.io/tovic/pen/ucxon

 
At Thursday, December 20, 2012 at 7:46:00 PM GMT+7, Blogger Rohis Facebook said...

makasih bnyk mas..., ntr insya ALlah sy coba, :D

 
At Saturday, April 13, 2013 at 9:22:00 PM GMT+7, Anonymous Anonymous said...

Maaf mas, saya masih baru belajar blog.Mohon bantuan. Cara pasangnya gimana yah?

 
At Tuesday, October 10, 2017 at 11:04:00 PM GMT+7, Blogger Giri Diwa Adam said...

Gan kok saya terapin di template blog saya kok nggak muncul ya tulisan sreachnya ?? mohon bantuanya

 

Post a Comment

<< Home