Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/WebApp/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.2/dist/confetti.browser.min.js"></script>
<script src="js/confetti.js"></script>
</body>

</html>
2 changes: 2 additions & 0 deletions src/WebApp/Components/Pages/Item/ItemPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@inject BasketState BasketState
@inject NavigationManager Nav
@inject IProductImageUrlProvider ProductImages
@inject IJSRuntime JSRuntime

@if (item is not null)
{
Expand Down Expand Up @@ -99,6 +100,7 @@ else if (notFound)
{
await BasketState.AddAsync(item);
await UpdateNumInCartAsync();
await JSRuntime.InvokeVoidAsync("triggerConfetti");
}
}

Expand Down
43 changes: 43 additions & 0 deletions src/WebApp/wwwroot/js/confetti.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Confetti animation function
window.triggerConfetti = function() {
if (typeof confetti !== 'undefined') {
// Fire confetti from both sides
var count = 200;
var defaults = {
origin: { y: 0.7 }
};

function fire(particleRatio, opts) {
confetti(Object.assign({}, defaults, opts, {
particleCount: Math.floor(count * particleRatio)
}));
}

fire(0.25, {
spread: 26,
startVelocity: 55,
});

fire(0.2, {
spread: 60,
});

fire(0.35, {
spread: 100,
decay: 0.91,
scalar: 0.8
});

fire(0.1, {
spread: 120,
startVelocity: 25,
decay: 0.92,
scalar: 1.2
});

fire(0.1, {
spread: 120,
startVelocity: 45,
});
}
};