Jangai commited on
Commit
8b542bc
·
verified ·
1 Parent(s): 61a6d43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -20
app.py CHANGED
@@ -27,15 +27,14 @@ html_code = """
27
  .planet:hover {
28
  transform: scale(1.2); /* Scale up the planet on hover */
29
  }
30
- .tooltip {
31
- position: fixed;
32
  background: rgba(0, 0, 0, 0.7);
33
  color: #fff;
34
  padding: 10px;
35
  border-radius: 5px;
36
- pointer-events: none;
37
- opacity: 0;
38
- transition: opacity 0.3s;
39
  }
40
  </style>
41
  </head>
@@ -46,8 +45,8 @@ html_code = """
46
  <div class="planet" id="venus" style="width: 30px; height: 30px; background: orange;"></div>
47
  <div class="planet" id="earth" style="width: 40px; height: 40px; background: blue;"></div>
48
  <div class="planet" id="mars" style="width: 30px; height: 30px; background: red;"></div>
49
- <div class="tooltip" id="tooltip"></div>
50
  </div>
 
51
  <script>
52
  const planets = [
53
  { id: 'sun', name: 'Sun', facts: 'The Sun is the star at the center of the Solar System.' },
@@ -57,22 +56,12 @@ html_code = """
57
  { id: 'mars', name: 'Mars', facts: 'Mars is known as the Red Planet due to its reddish appearance.' },
58
  ];
59
 
60
- const tooltip = document.getElementById('tooltip');
61
 
62
  planets.forEach(planet => {
63
  const element = document.getElementById(planet.id);
64
- element.addEventListener('mouseover', (event) => {
65
- tooltip.innerHTML = `<strong>${planet.name}</strong><br>${planet.facts}`;
66
- tooltip.style.opacity = 1;
67
- tooltip.style.top = `${event.clientY + 10}px`;
68
- tooltip.style.left = `${event.clientX + 10}px`;
69
- });
70
- element.addEventListener('mousemove', (event) => {
71
- tooltip.style.top = `${event.clientY + 10}px`;
72
- tooltip.style.left = `${event.clientX + 10}px`;
73
- });
74
- element.addEventListener('mouseout', () => {
75
- tooltip.style.opacity = 0;
76
  });
77
  });
78
 
@@ -109,7 +98,7 @@ demo = gr.Interface(
109
  inputs=[],
110
  outputs="html",
111
  title="Solar System Simulator",
112
- description="A colorful and animated solar system simulator. Hover over the planets to see key facts."
113
  )
114
 
115
  if __name__ == "__main__":
 
27
  .planet:hover {
28
  transform: scale(1.2); /* Scale up the planet on hover */
29
  }
30
+ .info-box {
 
31
  background: rgba(0, 0, 0, 0.7);
32
  color: #fff;
33
  padding: 10px;
34
  border-radius: 5px;
35
+ margin-top: 20px;
36
+ width: 100%;
37
+ text-align: center;
38
  }
39
  </style>
40
  </head>
 
45
  <div class="planet" id="venus" style="width: 30px; height: 30px; background: orange;"></div>
46
  <div class="planet" id="earth" style="width: 40px; height: 40px; background: blue;"></div>
47
  <div class="planet" id="mars" style="width: 30px; height: 30px; background: red;"></div>
 
48
  </div>
49
+ <div class="info-box" id="info-box">Click on a planet to see information</div>
50
  <script>
51
  const planets = [
52
  { id: 'sun', name: 'Sun', facts: 'The Sun is the star at the center of the Solar System.' },
 
56
  { id: 'mars', name: 'Mars', facts: 'Mars is known as the Red Planet due to its reddish appearance.' },
57
  ];
58
 
59
+ const infoBox = document.getElementById('info-box');
60
 
61
  planets.forEach(planet => {
62
  const element = document.getElementById(planet.id);
63
+ element.addEventListener('click', () => {
64
+ infoBox.innerHTML = `<strong>${planet.name}</strong><br>${planet.facts}`;
 
 
 
 
 
 
 
 
 
 
65
  });
66
  });
67
 
 
98
  inputs=[],
99
  outputs="html",
100
  title="Solar System Simulator",
101
+ description="A colorful and animated solar system simulator. Click on the planets to see key facts."
102
  )
103
 
104
  if __name__ == "__main__":