JavaScript商品列表

<style>
		* {
			margin: 0;
			padding: 0;
		}

		.box {
			width: 100%;
			height: 840px;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
		}

		.shopping {
			font-size: 20px;
			text-align: center;
		}


		.princess {
			width: 50%;
			height: 200px;
		}

		.princess img {
			width: 90%;
			height: 150px;
		}

		.princess div {
			font-weight: 900;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}

		.princess p {
			color: red;
			margin-top: 2%;
			font-size: 16px;
			font-weight: 900;
		}
	</style>
<script>
		    let xhr = new XMLHttpRequest();
		    xhr.open('get', 'js/lipstick.json', true);
		    xhr.send();
		    xhr.onreadystatechange = function() {
		        if (xhr.readyState == 4 && xhr.status == 200) {
		            let text = xhr.responseText;
		            console.log(text);
		            let data = JSON.parse(text);
		            console.log(data);
		            inner(data);
		        }
		    };
		
		    function inner(data) {
		        let str = ``;
		        for (let i = 0; i < data.length; i++) {
		            str += `
		                <div class="princess" onclick="clciks(${data[i].id})">
		                    <img src="${data[i].imge}" alt="">
		                    <div>${data[i].name}</div>
		                    <p>${data[i].pirce}</p>
		                </div>
		            `;
		        }
		        document.getElementsByClassName('box')[0].innerHTML = str;
		    }
		
		    function clciks(id) {
		        sessionStorage.setItem("focus", id);
		        location.href = 'spxqs.html';
		    }
		</script>

第二个页面

<style>
		* {
			margin: 0;
			padding: 0;
		}

		.title {
			width: 100%;
			height: 50px;
			font-size: 20px;
			font-weight: 700;
			position: relative;
		}

		.title div {
			margin-left: 10%;
		}

		.but {
			width: 30%;
			height: 30px;
			float: left;
		}

		.but img {
			width: 30px;
			position: absolute;
		}

		.banner {
			width: 100%;
			height: 300px;
			overflow: hidden;
			background-color: aqua;
		}

		.hateor {
			width: 500%;
			height: 300px;
			animation: beana 5s infinite;
		}

		.hateor img {
			width: 20%;
			height: 300px;
			float: left;
		}

		@keyframes beana {
			0% {
				margin-left: 0%;
			}

			25% {
				margin-left: -100%;
			}

			50% {
				margin-left: -200%;
			}

			70% {
				margin-left: -300%;
			}

			100% {
				margin-left: -400%;
			}
		}

		.introduce div {
			font-weight: 900;
		}

		.introduce p {
			color: red;
			margin-top: 2%;
			font-size: 20px;
			font-weight: 900;
		}

		.details {
			width: 100%;
			height: 350px;
			margin-top: 10%;
		}

		.details img {
			width: 90%;
			height: 350px;
			margin-left: 5%;
		}

		.content {
			width: 100%;
		}
	</style>
<script>
			let xhr = new XMLHttpRequest();
			xhr.open('get', 'js/lipstick.json', true);
			xhr.send();
			xhr.onreadystatechange = function() {
				if (xhr.readyState == 4 && xhr.status == 200) {
					let text = xhr.responseText;
					let data = JSON.parse(text);
					console.log(data);
					invoke(data);
				}
			};

			let details = sessionStorage.getItem('focus');
			console.log(details);

			function invoke(data) {
				let str = '';
				for (let i = 0; i < data.length; i++) {
					if (data[i].id == details) {
						str +=
							`<div class="banner">
		                        <div class="hateor">`
						for (let k = 0; k < data[i].imgs.length; k++) {
							str += `
		                            <img src="${data[i].imgs[k]}" alt="">`
						}

						str += `</div>
		                    </div>
		
		                    <div class="introduce">
		                        <div>
		                            ${data[i].name}
		                        </div>
		                        <p>
		                            ${data[i].pirce}
		                        </p>
		                    </div>
		
		                    <div class="details">`
						for (let k = 0; k < data[i].imgs.length; k++) {
							str += `
							    <img src="${data[i].imgs[k]}" alt="">`
						}

						str += `</div>`;
					}
				}
				document.getElementsByClassName('content')[0].innerHTML = str;
			}
		</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值