Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,7 +69,6 @@ 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 |
-
onmouseover="trackCursor(event)"
|
| 73 |
onclick="showPopup(event, '{dish['image']}', '{dish['name']}', '{dish['description']}')">
|
| 74 |
<img src='{dish['image']}' alt='{dish['name']}'
|
| 75 |
style='width: 100%; height: 140px; object-fit: cover; border-radius: 10px;'>
|
|
@@ -93,7 +92,7 @@ with gr.Blocks() as demo:
|
|
| 93 |
# Dish display area
|
| 94 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 95 |
|
| 96 |
-
# Pop-up HTML and JavaScript
|
| 97 |
gr.HTML("""
|
| 98 |
<div id="popup" style="display: none; position: absolute;
|
| 99 |
background-color: white; padding: 20px; border-radius: 10px;
|
|
@@ -105,29 +104,39 @@ with gr.Blocks() as demo:
|
|
| 105 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 106 |
</div>
|
| 107 |
<script>
|
| 108 |
-
|
| 109 |
-
let cursorY = 0;
|
| 110 |
-
|
| 111 |
-
// Track the cursor's position
|
| 112 |
-
function trackCursor(event) {
|
| 113 |
-
cursorX = event.pageX;
|
| 114 |
-
cursorY = event.pageY;
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
// Show the pop-up at the tracked cursor position
|
| 118 |
function showPopup(event, image, title, description) {
|
| 119 |
const popup = document.getElementById('popup');
|
| 120 |
-
document.getElementById('popup-image')
|
| 121 |
-
document.getElementById('popup-title')
|
| 122 |
-
document.getElementById('popup-description')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
//
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
|
|
|
|
|
|
| 128 |
popup.style.display = 'block';
|
| 129 |
}
|
| 130 |
|
|
|
|
| 131 |
function closePopup() {
|
| 132 |
const popup = document.getElementById('popup');
|
| 133 |
popup.style.display = 'none';
|
|
|
|
| 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;'>
|
|
|
|
| 92 |
# Dish display area
|
| 93 |
dish_display = gr.HTML(value=display_dishes("ALL"))
|
| 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;
|
|
|
|
| 104 |
color: white; border: none; border-radius: 5px; cursor: pointer;">Close</button>
|
| 105 |
</div>
|
| 106 |
<script>
|
| 107 |
+
// Show the pop-up at the cursor's position
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
function showPopup(event, image, title, description) {
|
| 109 |
const popup = document.getElementById('popup');
|
| 110 |
+
const popupImage = document.getElementById('popup-image');
|
| 111 |
+
const popupTitle = document.getElementById('popup-title');
|
| 112 |
+
const popupDescription = document.getElementById('popup-description');
|
| 113 |
+
|
| 114 |
+
// Update the pop-up content
|
| 115 |
+
popupImage.src = image;
|
| 116 |
+
popupTitle.textContent = title;
|
| 117 |
+
popupDescription.textContent = description;
|
| 118 |
+
|
| 119 |
+
// Set the pop-up position based on cursor location
|
| 120 |
+
const popupWidth = 300; // Width of the pop-up
|
| 121 |
+
const xOffset = 10; // Offset to avoid overlapping cursor
|
| 122 |
+
const yOffset = 20; // Offset to place pop-up below the cursor
|
| 123 |
+
let xPos = event.pageX + xOffset;
|
| 124 |
+
let yPos = event.pageY + yOffset;
|
| 125 |
|
| 126 |
+
// Prevent the pop-up from going off the screen
|
| 127 |
+
if (xPos + popupWidth > window.innerWidth) {
|
| 128 |
+
xPos = window.innerWidth - popupWidth - xOffset;
|
| 129 |
+
}
|
| 130 |
+
if (yPos + popup.offsetHeight > window.innerHeight) {
|
| 131 |
+
yPos = window.innerHeight - popup.offsetHeight - yOffset;
|
| 132 |
+
}
|
| 133 |
|
| 134 |
+
popup.style.left = `${xPos}px`;
|
| 135 |
+
popup.style.top = `${yPos}px`;
|
| 136 |
popup.style.display = 'block';
|
| 137 |
}
|
| 138 |
|
| 139 |
+
// Close the pop-up
|
| 140 |
function closePopup() {
|
| 141 |
const popup = document.getElementById('popup');
|
| 142 |
popup.style.display = 'none';
|