js点击图片实现查看大图
Here is my html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- E-Commerce
Author: Ngai Ka Po
Date: 20/11/2024
-->
<title>Final Project Cycle1</title>
<link rel="stylesheet" href="css/style.css">
<link rel="icon" href="images/Shop_logo1.png" type="image/png" sizes="16x16">
<style>
.center {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
<script>
function process(fm) {
alert("Username length: " + document.querySelector("#username").value.length);
alert("Qty: " + fm.qty.value);
if (document.querySelector("#username").value.length < 1) {
alert("Please enter UserName");
document.querySelector("#username").focus();
return false;
} else {
fm.f_username.value = document.querySelector("#username").value;
}
if (fm.qty.value < 1) {
alert("QTY not selected, please select QTY");
fm.qty.focus();
return false;
}
var url = "http://localhost:3000/add_cart?prod_id=" + fm.prod_id.value + "&qty=" + fm.qty.value + "&price=" + fm.price.value + "&f_username=" + fm.f_username.value;
alert("url: " + url);
/*
alert("Return false, not actually making a call");
return false; // Uncomment and change to return true; to actually make a call
*/
alert("return true: actually call program");
return true;
}
function process_check_out(fm) {
alert("Username length: " + document.querySelector("#username").value.length);
if (document.querySelector("#username").value.length < 1) {
alert("Please enter UserName");
document.querySelector("#username").focus();
return false;
} else {
fm.f_check_out_username.value = document.querySelector("#username").value;
}
var url = "http://localhost:3000/check_out?f_check_out_username=" + fm.f_check_out_username.value;
alert("url: " + url);
/*
alert("Return false, not actually making a call");
return false;
*/
alert("return true: actually call program");
return true;
}
function login(fm) {
alert("Username length: " + document.querySelector("#username").value.length);
alert("Password length: " + document.querySelector("#password").value.length);
if (document.querySelector("#username").value.length < 1) {
alert("Please enter UserName");
document.querySelector("#username").focus();
return false;
}
if (document.querySelector("#password").value.length < 1) {
alert("Please enter Password");
document.querySelector("#password").focus();
return false;
}
var url = "http://localhost:3000/login?username=" + fm.username.value + "&password=" + fm.password.value;
alert("url: " + url);
/*
alert("Return false, not actually making a call");
return false;
*/
alert("return true: actually call program");
return true;
}
</script>
</head>
<body>
<header>
<nav>
<ul>
<li><a href="http://localhost:3000/">Home</a></li>
<li><a href="http://localhost:3000/view_catalog">Shopping Cart</a></li>
</ul>
</nav>
<img src="images/Shop_logo1.png" alt="Shop Logo" width="150" height="100" class="center">
</header>
<main>
<section class="mission">
<article>
<h2>Our Mission</h2>
<p>Our mission is to create a vibrant community for Gunpla enthusiasts.</p>
<p>We strive to offer high-quality products, helpful resources,<br> and a platform for builders to share
their creativity and skills.</p>
<p>All sales Final - No refund or exchange.</p>
<p>Once we received your payment, we will contact you for delivery.</p>
</article>
</section>
<section class="products">
<h1>Items for sale!</h1>
</section>
<!-- Username Field -->
<div class="container">
<form name="f0" id="f0" method="get" target="_blank" action="http://localhost:3000/login"
onsubmit="return login(this)">
<p>
Customer User Name:
<input type="text" name="username" id="username" value="">
</p>
<p>
Password:
<input type="password" name="password" id="password">
</p>
<p>
<input type="submit" value="Login">
</p>
</form>
</div>
<!-- Product 1 Form -->
<form name="f1" id="f1" method="get" target="_blank" action="http://localhost:3000/add_cart"
onsubmit="return process(this)">
<table border="2">
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Unit Price</th>
<th>Action</th>
</tr>
<tr>
<td>
<img src="images/prod1.jpg" alt="Strike Freedom Gundam" class="product-image">
<p>MGEX Strike Freedom Gundam</p>
<input type="hidden" name="prod_id" id="prod_id" value="1">
</td>
<td>
<select name="qty" id="qty">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</td>
<td>$170<input type="hidden" name="price" id="price" value="170"></td>
<td><input type="hidden" name="f_username" id="f_username" value="">
<input type="submit" value="Add to shopping cart">
</td>
</tr>
</table>
</form>
<!-- Product 2 Form -->
<form name="f2" id="f2" method="get" target="_blank" action="http://localhost:3000/add_cart"
onsubmit="return process(this)">
<table border="2">
<tr>
<td>
<img src="images/prod2.jpg" alt="Nu Gundam (Ver. Ka)" class="product-image">
<p>MG Nu Gundam (Ver. Ka)</p>
<input type="hidden" name="prod_id" id="prod_id" value="2">
</td>
<td>
<select name="qty" id="qty">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</td>
<td>$85.71<input type="hidden" name="price" id="price" value="85.71"></td>
<td><input type="hidden" name="f_username" id="f_username" value="">
<input type="submit" value="Add to shopping cart">
</td>
</tr>
</table>
</form>
<!-- Product 3 Form -->
<form name="f3" id="f3" method="get" target="_blank" action="http://localhost:3000/add_cart"
onsubmit="return process(this)">
<table border="2">
<tr>
<td>
<img src="images/prod3.jpg" alt="Unicorn Gundam" class="product-image">
<p>RG #25 RX-0 Unicorn Gundam</p>
<input type="hidden" name="prod_id" id="prod_id" value="3">
</td>
<td>
<select name="qty" id="qty">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</td>
<td>$49.08<input type="hidden" name="price" id="price" value="49.08"></td>
<td><input type="hidden" name="f_username" id="f_username" value="">
<input type="submit" value="Add to shopping cart">
</td>
</tr>
</table>
</form>
<br />
<form name="f_checkout" id="f_checkout" method="get" action="http://localhost:3000/check_out"
onsubmit="return process_check_out(this)">
<input type="hidden" name="f_check_out_username" id="f_check_out_username" value="">
<input type="submit" value="Check out - Use Paypal">
</form>
<h1 id="txt1"></h1>
</main>
<footer>
<img src="images/Shop_logo1.png" width="150" height="100">
<h3>Contact Us</h3>
<p>Email:
[email protected]</p>
<p>Phone: (123) 456-7890</p>
</footer>
</body>
</html>
Here is my CSS:
/* Global Settings for Animation */
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
padding: 0;
overflow-x: hidden;
}
/* Fade-in animation for header */
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-50px);
/* Start 50px above */
}
to {
opacity: 1;
transform: translateY(0);
/* End at its original position */
}
}
header {
background-color: #5F6F52;
height: 100px;
width: 100%;
position: fixed;
animation: fadeIn 1.5s ease-out;
/* Applies the updated fadeIn animation */
top: 0;
left: 0;
z-index: 10;
/* Ensures the header stays on top */
}
header ul {
position: absolute;
right: 5vw;
top: 0;
line-height: 80px;
}
header li {
display: inline;
margin-right: 4vw;
}
header a {
color: rgb(0, 0, 0);
text-decoration: none;
transition: color 0.3s ease, transform 0.3s ease;
/* Smooth transition for color and scale */
}
header a:hover {
color: lightgrey;
text-decoration: underline;
transform: scale(1.1);
/* Slightly enlarges the button on hover */
}
/* Slide-in animation for mission section */
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-50px);
/* Start above */
}
to {
opacity: 1;
transform: translateY(0);
/* End at its original position */
}
}
.mission {
background-color: rgb(58, 85, 57);
color: white;
height: 95vh;
background-image: url("/images/Background.png");
background-repeat: no-repeat;
background-size: cover;
background-position: center;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
animation: slideIn 1.5s ease-out;
/* Applies the updated slideIn animation */
margin-top: 100px;
/* Adds spacing below the fixed header */
}
.products {
text-align: center;
font-size: 1.5em;
padding: 20px;
}
.products a {
color: #5F6F52;
text-decoration: none;
transition: color 0.3s ease, transform 0.3s ease;
}
.products a:hover {
color: lightgrey;
text-decoration: underline;
transform: scale(1.1);
}
.container {
text-align: center;
margin: 20px auto;
}
#username,
#password,
input[type="submit"] {
display: block;
margin: 10px auto;
}
#username,
#password {
display: block;
margin: 20px auto;
padding: 12px;
width: 50%;
max-width: 300px;
border: 2px solid #5F6F52;
border-radius: 6px;
text-align: center;
font-size: 16px;
font-weight: bold;
background-color: #f9f9f9;
box-shadow: grey 0px 0px 3px;
transition: border-color 0.3s;
}
/* Style for the shopping cart table */
table {
width: 80%;
margin: 20px auto;
border-collapse: separate;
font-family: Arial, sans-serif;
font-size: 16px;
table-layout: fixed;
border: none;
border-radius: 10px;
overflow: hidden;
box-shadow: grey 0px 0px 3px;
border-spacing: 0; /* Ensures no gaps between cells */
}
th,
td {
padding: 12px 15px;
text-align: center;
border-bottom: 1px solid #ddd;
width: 25%;
}
th {
background-color: #5F6F52;
color: white;
}
/* Add rounded corners to the first and last th */
th:first-child {
border-top-left-radius: 10px;
}
th:last-child {
border-top-right-radius: 10px;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
tr:hover {
background-color: #f1f1f1;
}
/* Image styling */
.product-image {
display: block;
margin: 0 auto;
width: 150px; /* Adjust width as needed */
height: auto;
border-radius: 5px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
}
/* Center align text below the image */
td p {
margin: 10px 0 0 0;
text-align: center;
font-weight: bold;
font-size: 14px;
}
/* Style for the checkout button */
input[type="submit"] {
display: block;
margin: 10px auto;
background-color: #5F6F52;
color: white;
padding: 8px 16px;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s ease, transform 0.3s ease;
margin-top: 10px;
box-shadow: grey 0px 0px 3px;
}
input[type="submit"]:hover {
background-color: #4b5e43;
transform: scale(1.05);
}
/* Center the footer logo and contact information */
footer {
background-color: #5F6F52;
color: white;
text-align: center;
padding: 20px;
position: relative;
}
footer img {
display: block;
margin: 0 auto 10px auto;
width: 100px;
height: auto;
}
footer h3,
footer p {
margin: 5px 0;
font-size: 14px;
}
/* Responsive Design */
@media (max-width: 768px) {
#username,
#password {
width: 80%;
font-size: 14px;
}
table {
width: 100%;
font-size: 14px;
}
th,
td {
padding: 10px;
}
input[type="submit"] {
font-size: 12px;
padding: 6px 12px;
}
}