-
Notifications
You must be signed in to change notification settings - Fork 113
[Feature]: Add Glassmorphism Effect Option #79 #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shreyashpatel5506
wants to merge
6
commits into
prem-k-r:main
Choose a base branch
from
shreyashpatel5506:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
86bad03
[Feature]: Add Glassmorphism Effect Option #79
shreyashpatel5506 4c4096f
updated
shreyashpatel5506 eff0107
updated
shreyashpatel5506 2d95b87
resolve conflict
shreyashpatel5506 307e863
change
shreyashpatel5506 d0ff93b
Merge branch 'main' into main
shreyashpatel5506 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| * Glassmorphism feature | ||
| * Adds optional backdrop blur and supports a toggle + blur intensity slider | ||
| */ | ||
|
|
||
| const glassCheckbox = document.getElementById("glassCheckbox"); | ||
| const glassBar = document.querySelector("#glassBlurControl .opacityBar"); | ||
| const glassSlider = document.getElementById("glassSlider"); | ||
| const glassBlurLevel = document.getElementById("glassBlurLevel"); | ||
|
|
||
| const MAX_BLUR = parseInt(getComputedStyle(document.documentElement).getPropertyValue('--glass-max-blur')) || 30; | ||
|
|
||
| function setGlassBlur(px) { | ||
| const clamped = Math.max(0, Math.min(MAX_BLUR, Math.round(px))); | ||
| const percent = (clamped / MAX_BLUR) * 100; | ||
| glassSlider.style.width = `${percent}%`; | ||
| glassBlurLevel.textContent = `${clamped}px`; | ||
| document.documentElement.style.setProperty('--glass-blur', `${clamped}px`); | ||
| localStorage.setItem('glassBlur', clamped); | ||
| } | ||
|
|
||
| function setGlassEnabled(enabled) { | ||
| const control = document.getElementById('glassBlurControl'); | ||
| if (enabled) { | ||
| document.documentElement.classList.add('glass-enabled'); | ||
| localStorage.setItem('glassEnabled', '1'); | ||
| if (control) control.classList.remove('disabled'); | ||
| if (glassSlider) glassSlider.setAttribute('aria-disabled', 'false'); | ||
| if (glassCheckbox) glassCheckbox.setAttribute('aria-checked', 'true'); | ||
| } else { | ||
| document.documentElement.classList.remove('glass-enabled'); | ||
| localStorage.setItem('glassEnabled', '0'); | ||
| if (control) control.classList.add('disabled'); | ||
| if (glassSlider) glassSlider.setAttribute('aria-disabled', 'true'); | ||
| if (glassCheckbox) glassCheckbox.setAttribute('aria-checked', 'false'); | ||
| } | ||
| } | ||
|
|
||
| // Drag / click handling (similar to other sliders in the project) | ||
| function handleGlassDrag(e) { | ||
| const clientX = e.type.startsWith("touch") ? e.touches[0].clientX : e.clientX; | ||
| const rect = glassBar.getBoundingClientRect(); | ||
| let newPos = clientX - rect.left; | ||
| newPos = Math.max(0, Math.min(rect.width, newPos)); | ||
| const percentage = +((newPos / rect.width) * 100).toFixed(2); | ||
| const px = (percentage / 100) * MAX_BLUR; | ||
| setGlassBlur(px); | ||
| } | ||
|
|
||
| function startGlassDrag() { | ||
| const onMove = e => handleGlassDrag(e); | ||
| const onEnd = () => { | ||
| ["mousemove", "touchmove"].forEach(evt => document.removeEventListener(evt, onMove)); | ||
| ["mouseup", "touchend"].forEach(evt => document.removeEventListener(evt, onEnd)); | ||
| }; | ||
| ["mousemove", "touchmove"].forEach(evt => document.addEventListener(evt, onMove)); | ||
| ["mouseup", "touchend"].forEach(evt => document.addEventListener(evt, onEnd)); | ||
| } | ||
|
|
||
| ["mousedown", "touchstart"].forEach(evt => { | ||
| glassBar.addEventListener(evt, e => { | ||
| e.preventDefault(); | ||
| handleGlassDrag(e); | ||
| startGlassDrag(); | ||
| }, { passive: false }); | ||
| }); | ||
shreyashpatel5506 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Initialize from saved state | ||
| const savedGlassEnabled = localStorage.getItem('glassEnabled') === '1'; | ||
| const savedGlassBlur = Number(localStorage.getItem('glassBlur')) || 8; | ||
|
|
||
| setGlassBlur(savedGlassBlur); | ||
| setGlassEnabled(savedGlassEnabled); | ||
| if (glassCheckbox) glassCheckbox.checked = savedGlassEnabled; | ||
|
|
||
| // Wire up the checkbox | ||
| if (glassCheckbox) { | ||
| glassCheckbox.setAttribute('role', 'switch'); | ||
| glassCheckbox.setAttribute('aria-label', 'Toggle glassmorphism'); | ||
| glassCheckbox.addEventListener('change', () => { | ||
| setGlassEnabled(glassCheckbox.checked); | ||
| }); | ||
| } | ||
|
|
||
| // Initialize disabled state for the control if needed | ||
| const glassBlurControl = document.getElementById('glassBlurControl'); | ||
| if (glassBlurControl) { | ||
| // reflect current enabled state | ||
| if (!savedGlassEnabled) glassBlurControl.classList.add('disabled'); | ||
| } | ||
|
|
||
| // Expose a small API for other scripts if needed | ||
| window.glassmorphism = { | ||
| setEnabled: setGlassEnabled, | ||
| setBlur: setGlassBlur, | ||
| }; | ||
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.