Skip to content

Commit

Permalink
Merge pull request #5 from 7PH/dev/hover-effect
Browse files Browse the repository at this point in the history
#4: Add playMode to support hover-triggered and hover-only effects
  • Loading branch information
7PH authored Sep 1, 2022
2 parents 5c2e05e + f3c01f4 commit 8ca955e
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 61 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rules:
indent:
- error
- 4
- SwitchCase: 1
linebreak-style:
- error
- unix
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src="./assets/intro.gif">

PowerGlitch is a standalone library with no external dependencies. It leverages CSS animations to create a glitch effect on images. No canvas or DOM manipulations are needed. It weights around 1.8kb minified and gzipped and 4kb minified.<br>
PowerGlitch is a standalone library with no external dependencies. It leverages CSS animations to create a glitch effect on images. No canvas or DOM manipulations are needed. It weights less than 2kb minified and gzipped.<br>

Want to try it out? Check out the [demo](https://7ph.github.io/powerglitch/#/playground) 😊

Expand Down
2 changes: 1 addition & 1 deletion dist/powerglitch.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs-src/src/components/ImagePreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const rebuild = () => {
// Rebuild when mounted or options changed
onMounted(rebuild);
watch(rebuild);
watch(appStore.powerGlitchOptions, rebuild);
</script>

<template>
Expand Down
36 changes: 33 additions & 3 deletions docs-src/src/components/OptionPanel.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup>
import { ref, onMounted } from 'vue';
import { PowerGlitch } from '../../../src/index.ts';
import { useAppStore } from '@/stores/app';
import ToggleGroupOption from '@/components/ToggleGroupOption.vue';
import StringOption from '@/components/StringOption.vue';
Expand All @@ -8,10 +9,33 @@ import BooleanOption from '@/components/BooleanOption.vue';
import NumberOption from '@/components/NumberOption.vue';
const appStore = useAppStore();
const setFullDefaults = (playMode) => {
const defaults = PowerGlitch.getDefaultOptions(playMode);
appStore.powerGlitchOptions.playMode = playMode;
appStore.powerGlitchOptions.timing = defaults.timing;
appStore.powerGlitchOptions.glitchTimeSpan = defaults.glitchTimeSpan;
appStore.powerGlitchOptions.shake = defaults.shake;
appStore.powerGlitchOptions.slice = defaults.slice;
};
</script>

<template>
<div class="px-4">
<div class="font-bold mt-6 mb-2 pl-2">
Recommended defaults
</div>
<div class="ml-4 flex flex-wrap justify-center gap-2">
<button @click="setFullDefaults('always')">
Infinite
</button>
<button @click="setFullDefaults('hover-triggered')">
Once on hover
</button>
<button @click="setFullDefaults('hover-only')">
Always on hover
</button>
</div>
<div class="font-bold mt-6 mb-2 pl-2">
Global
</div>
Expand All @@ -20,6 +44,12 @@ const appStore = useAppStore();
class="mt-1"
:title="'Image'"
/>
<SelectOption
v-model="appStore.powerGlitchOptions.playMode"
class="mt-1"
:title="'Activate'"
:values="['always', 'hover-triggered', 'hover-only']"
/>
<StringOption
v-model="appStore.powerGlitchOptions.backgroundColor"
class="mt-1"
Expand Down Expand Up @@ -81,7 +111,7 @@ const appStore = useAppStore();
<ToggleGroupOption
v-model="appStore.powerGlitchOptions.glitchTimeSpan"
:title="'Enabled'"
:getDefaultValue="v => v ? PowerGlitch.getDefaultOptions().glitchTimeSpan : false"
:getDefaultValue="v => v ? PowerGlitch.getDefaultOptions(appStore.powerGlitchOptions.playMode).glitchTimeSpan : false"
/>
<template v-if="appStore.powerGlitchOptions.glitchTimeSpan">
<NumberOption
Expand Down Expand Up @@ -110,7 +140,7 @@ const appStore = useAppStore();
<ToggleGroupOption
v-model="appStore.powerGlitchOptions.shake"
:title="'Enabled'"
:getDefaultValue="v => v ? PowerGlitch.getDefaultOptions().shake : false"
:getDefaultValue="v => v ? PowerGlitch.getDefaultOptions(appStore.powerGlitchOptions.playMode).shake : false"
/>
<template v-if="appStore.powerGlitchOptions.shake">
<NumberOption
Expand Down Expand Up @@ -147,7 +177,7 @@ const appStore = useAppStore();
<ToggleGroupOption
v-model="appStore.powerGlitchOptions.slice"
:title="'Enabled'"
:getDefaultValue="v => v ? PowerGlitch.getDefaultOptions().slice : false"
:getDefaultValue="v => v ? PowerGlitch.getDefaultOptions(appStore.powerGlitchOptions.playMode).slice : false"
/>
<template v-if="appStore.powerGlitchOptions.slice">
<NumberOption
Expand Down
2 changes: 1 addition & 1 deletion docs-src/src/stores/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useAppStore = defineStore('main', {
* Default options for Power Glitch
*/
powerGlitchOptions: {
...PowerGlitch.getDefaultOptions(),
...PowerGlitch.getDefaultOptions('always'),
imageUrl: defaultImage,
},
}),
Expand Down
2 changes: 1 addition & 1 deletion docs-src/src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ onMounted(() => {
❓ Introduction
</h1>
<p class="mt-4">
PowerGlitch is a standalone library with no external dependencies. It leverages CSS animations to create a glitch effect on images. No canvas or DOM manipulations are needed. It weights around <b>1.8kb</b> minified and gzipped and <b>4kb</b> minified.<br>
PowerGlitch is a standalone library with no external dependencies. It leverages CSS animations to create a glitch effect on images. No canvas or DOM manipulations are needed. It weights less than <b>2kb</b> minified and gzipped.<br>
<br>
What are you waiting for?
<RouterLink
Expand Down
2 changes: 1 addition & 1 deletion docs-src/src/views/PlaygroundView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ onMounted(() => {
PowerGlitch.glitch(
logoGlitch.value,
{
...PowerGlitch.getDefaultOptions(),
...PowerGlitch.getDefaultOptions('always'),
imageUrl: logo,
}
);
Expand Down
1 change: 1 addition & 0 deletions docs-src/src/views/UsageView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ PowerGlitch.glitch(
'div.glitch',
{
imageUrl: 'https://.../image.png',
playMode: 'always',
backgroundColor: 'transparent',
hideOverflow: true,
timing: {
Expand Down
41 changes: 21 additions & 20 deletions docs/assets/index.a43de88f.js → docs/assets/index.b2848580.js

Large diffs are not rendered by default.

Loading

0 comments on commit 8ca955e

Please sign in to comment.