Skip to content

Commit

Permalink
add animation script
Browse files Browse the repository at this point in the history
  • Loading branch information
namnguyen20999 committed Dec 4, 2024
1 parent ce45291 commit 5cc7c11
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
7 changes: 5 additions & 2 deletions doc/gui/extension/example_library/example_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ExampleLibrary(ElementLibrary):
def __init__(self) -> None:
# Initialize the set of visual elements for this extension library

logo_path = self.get_resource("resources/taipy_logo.png")
logo_path = self.get_resource("assets/logo.png")
with open(logo_path, "rb") as f:
logo_base64 = base64.b64encode(f.read()).decode("utf-8")

Expand Down Expand Up @@ -91,4 +91,7 @@ def get_elements(self) -> dict:

def get_scripts(self) -> list[str]:
# Only one JavaScript bundle for this library.
return ["front-end/dist/exampleLibrary.js"]
return [
"front-end/dist/exampleLibrary.js",
"front-end/scripts/logoAnimation.js",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const style = document.createElement('style');
style.innerHTML = `
@keyframes logoAnimation {
from {
transform: scale(1);
}
to {
transform: scale(1.5);
}
}
.logo-animate {
animation: logoAnimation 2s infinite alternate;
}
`;
document.head.appendChild(style);

document.addEventListener("DOMContentLoaded", () => {
const checkForElement = setInterval(() => {
const logoImage = document.querySelector('img[alt="LogoWithText"]');
if (logoImage) {
logoImage.classList.add('logo-animate');
clearInterval(checkForElement);
}
}, 100);
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const styles = {
alignItems: "center",
},
logo: {
width: "1em",
height: "1em",
width: "4em",
height: "4em",
marginRight: "10px",
},
};
Expand All @@ -26,7 +26,7 @@ const LogoWithText = ({ text, defaultText, logoPath }: CaptionProps) => {
<div style={styles.container}>
<img
src={`data:image/png;base64,${logoPath}`}
alt="LogoWithText Image"
alt="LogoWithText"
style={styles.logo}
/>
<div>{value}</div>
Expand Down

0 comments on commit 5cc7c11

Please sign in to comment.