On lines 1161-1176 and 1190-1206 in the css file and lines 58-67 in the js file, when I click on the search logo nothing happens.
Yet, I expect the search bar to appear like the video when you click on it.
Code Snippet – Full GitHub Repository
/* lines 58-67 */
const searchButton = document.querySelector('.t-search'),
tClose = document.querySelector('.search-close'),
showClass = document.querySelector('.site');
searchButton.addEventListener('click', function() {
showClass.classList.toggle('showsearch')
})
/* lines 1161-1176 */
.search-bottom {
position: fixed;
bottom: 60px;
width: var(--percent100);
padding: 2.5em 0;
background-color: var(--secondary-dark-color);
z-index: 1000;
visibility: hidden;
opacity: 0;
will-change: visibility, opacity;
}
.showsearch .search-bottom {
visibility: inherit;
opacity: 1;
}
/* lines 1190-1206 */
.overlay {
position: fixed;
width: var(--percent100);
height: var(--percent100);
top: 0;
left: 0;
z-index: 999;
background-color: rgba(0, 0, 0, 0.4);
visibility: hidden;
opacity: 0;
will-change: visibility, opacity;
}
.showmenu .overlay {
opacity: 1;
visibility: inherit;
}
2
Answers
I have identified the issue and implemented a solution to address the problem.
The bug stemmed from the application of the
showsearch
class to a div with the classsite
while attempting to display the search input field through CSS. The initial CSS code used was ineffective because the.showsearch
class was not a descendant child of.site
.It will looks like this when the class is toggled.
To resolve this, I recommend adding the
showsearch
class to the body instead of toggling it on the.site
div. Here is the modified JavaScript snippet:This adjustment ensures that the
.showsearch
class is toggled on thebody
element, resulting in the following structure:Additionally, I observed that the
overlay
is not visible whenshowmenu
is toggled. To rectify this, I recommend modifying thequerySelector
in theshow mobile menu
section atline 20
to include the overlay:This adjustment ensures that the
overlay
is displayed when the mobile menu is toggled.Also add
transition: opacity 0.4s, visibility 0.4s;
to both.search-bottom
and.overlay
to have a smooth transition.The
will-change
CSS property is used to inform the browser that an element is expected to change in the future, allowing the browser to make optimizations for smoother animations and transitions. However, there are some considerations and potential reasons whywill-change
might not work as expected:Unsupported Properties or Elements:
will-change
. It’s most effective for properties liketransform
andopacity
that are commonly used in animations. Applying it to properties that don’t trigger GPU acceleration may not provide performance improvements.Overuse of
will-change
:will-change
to too many elements or properties can have adverse effects. It’s meant to be used selectively on elements that are known to cause performance issues, rather than as a blanket rule for all elements.Early Optimization:
will-change
prematurely might not yield noticeable benefits. It’s recommended to use it only when performance issues arise and profiling indicates a need for optimization.Hardware Acceleration Support:
will-change
is most effective when the browser supports hardware acceleration. However, not all browsers or devices may provide the same level of hardware acceleration. Ensure that the browser and device you’re testing on support hardware acceleration.Correct Syntax and Usage:
will-change
. It is usually applied to the element you expect to change, like this:Animations and Transitions:
will-change
property.Testing in Browser DevTools:
will-change
is having the desired effect, such as GPU acceleration.Here’s an example of how you might use
will-change
for a CSS transition:Remember that browser rendering behavior can vary, and
will-change
is just one tool among many for optimizing performance. Use it judiciously and in conjunction with other performance optimization techniques based on your specific use case and requirements.