1
1
mirror of https://github.com/neosubhamoy/neosubhamoy-portfolio.git synced 2025-12-20 01:09:35 +05:30

(feat): improved serchbar open, close animation and added blurry search background (refactor): updated flotingbar config

This commit is contained in:
2023-11-06 20:15:45 +05:30
parent 448700e364
commit 211d40affc
5 changed files with 87 additions and 40 deletions

View File

@@ -3,6 +3,8 @@ const floatingBar = document.getElementById("floating-bar");
const searchBar = document.getElementById("searchbar");
const shareBtn = document.getElementById("sharebutton");
const closeBtn = document.getElementById("closebutton");
const searchTxt = document.getElementById("searchtext");
const searchInput = document.getElementById("searchinput");
let lastScrollTop = 0;
window.addEventListener("scroll", function () {
@@ -24,46 +26,53 @@ window.addEventListener("scroll", function () {
});
// function to open floating search window
function activate_search(searchBar, floatingBar, closeBtn, shareBtn) {
function activate_search(searchBar, floatingBar, closeBtn, shareBtn, searchTxt, searchInput) {
floatingBar.classList.remove("floatingbar-click-slide-down");
floatingBar.classList.add("floatingbar-click-slide-up");
searchBar.classList.remove("searchbar-click-decrease-width");
searchBar.classList.add("searchbar-click-increase-width");
closeBtn.classList.remove("hidden");
shareBtn.classList.add("hidden");
searchTxt.classList.add("hidden");
searchInput.classList.remove("hidden");
searchInput.focus();
document.body.classList.add("overflow-hidden");
}
// function to close floating search window
function close_search(searchBar, floatingBar, closeBtn, shareBtn) {
function close_search(searchBar, floatingBar, closeBtn, shareBtn, searchTxt, searchInput) {
floatingBar.classList.remove("floatingbar-click-slide-up");
floatingBar.classList.add("floatingbar-click-slide-down");
searchBar.classList.remove("searchbar-click-increase-width");
searchBar.classList.add("searchbar-click-decrease-width");
closeBtn.classList.add("hidden");
shareBtn.classList.remove("hidden");
searchTxt.classList.remove("hidden");
searchInput.classList.add("hidden");
document.body.classList.remove("overflow-hidden");
}
// when the search icon is clicked
searchBar.addEventListener("click", function () {
activate_search(searchBar, floatingBar, closeBtn, shareBtn);
activate_search(searchBar, floatingBar, closeBtn, shareBtn, searchTxt, searchInput);
});
// when ALT + K shortcut key is pressed
document.addEventListener("keydown", function(event) {
if (event.altKey && event.key === "k") {
activate_search(searchBar, floatingBar, closeBtn, shareBtn);
activate_search(searchBar, floatingBar, closeBtn, shareBtn, searchTxt, searchInput);
}
});
// when close button is clicked
closeBtn.addEventListener("click", function () {
close_search(searchBar, floatingBar, closeBtn, shareBtn);
close_search(searchBar, floatingBar, closeBtn, shareBtn, searchTxt, searchInput);
});
// when ESC key is pressed
document.addEventListener("keydown", function(event) {
if (event.key === "Escape") {
close_search(searchBar, floatingBar, closeBtn, shareBtn);
close_search(searchBar, floatingBar, closeBtn, shareBtn, searchTxt, searchInput);
}
});