Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,7 +69,7 @@ def display_dishes(category):
|
|
| 69 |
html_content += f"""
|
| 70 |
<div style='width: 220px; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
|
| 71 |
background-color: #f9f9f9; text-align: center; cursor: pointer;'
|
| 72 |
-
onclick="showPopup('{dish['image']}', '{dish['name']}', '{dish['description']}')">
|
| 73 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 74 |
style='width: 100%; height: 140px; object-fit: cover; border-radius: 10px;'>
|
| 75 |
<h4 style='margin: 10px 0; color: #444;'>{dish['name']}</h4>
|
|
@@ -94,7 +94,7 @@ with gr.Blocks() as demo:
|
|
| 94 |
|
| 95 |
# Pop-up HTML and JavaScript
|
| 96 |
gr.HTML("""
|
| 97 |
-
<div id="popup" style="display: none; position:
|
| 98 |
background-color: white; padding: 20px; border-radius: 10px;
|
| 99 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 300px;">
|
| 100 |
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
|
@@ -104,15 +104,22 @@ with gr.Blocks() as demo:
|
|
| 104 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 105 |
</div>
|
| 106 |
<script>
|
| 107 |
-
function showPopup(image, title, description) {
|
| 108 |
const popup = document.getElementById('popup');
|
| 109 |
document.getElementById('popup-image').src = image;
|
| 110 |
document.getElementById('popup-title').textContent = title;
|
| 111 |
document.getElementById('popup-description').textContent = description;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
popup.style.display = 'block';
|
| 113 |
}
|
|
|
|
| 114 |
function closePopup() {
|
| 115 |
-
document.getElementById('popup')
|
|
|
|
| 116 |
}
|
| 117 |
</script>
|
| 118 |
""")
|
|
|
|
| 69 |
html_content += f"""
|
| 70 |
<div style='width: 220px; padding: 10px; border: 1px solid #ddd; border-radius: 10px;
|
| 71 |
background-color: #f9f9f9; text-align: center; cursor: pointer;'
|
| 72 |
+
onclick="showPopup(event, '{dish['image']}', '{dish['name']}', '{dish['description']}')">
|
| 73 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 74 |
style='width: 100%; height: 140px; object-fit: cover; border-radius: 10px;'>
|
| 75 |
<h4 style='margin: 10px 0; color: #444;'>{dish['name']}</h4>
|
|
|
|
| 94 |
|
| 95 |
# Pop-up HTML and JavaScript
|
| 96 |
gr.HTML("""
|
| 97 |
+
<div id="popup" style="display: none; position: absolute;
|
| 98 |
background-color: white; padding: 20px; border-radius: 10px;
|
| 99 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); z-index: 1000; text-align: center; width: 300px;">
|
| 100 |
<img id="popup-image" src="" alt="" style="width: 100%; height: auto; border-radius: 10px;">
|
|
|
|
| 104 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 105 |
</div>
|
| 106 |
<script>
|
| 107 |
+
function showPopup(event, image, title, description) {
|
| 108 |
const popup = document.getElementById('popup');
|
| 109 |
document.getElementById('popup-image').src = image;
|
| 110 |
document.getElementById('popup-title').textContent = title;
|
| 111 |
document.getElementById('popup-description').textContent = description;
|
| 112 |
+
|
| 113 |
+
// Set the position of the popup based on the cursor's location
|
| 114 |
+
popup.style.left = `${event.pageX}px`;
|
| 115 |
+
popup.style.top = `${event.pageY}px`;
|
| 116 |
+
|
| 117 |
popup.style.display = 'block';
|
| 118 |
}
|
| 119 |
+
|
| 120 |
function closePopup() {
|
| 121 |
+
const popup = document.getElementById('popup');
|
| 122 |
+
popup.style.display = 'none';
|
| 123 |
}
|
| 124 |
</script>
|
| 125 |
""")
|