script部分
<script type="text/javascript" src="../js/jquery-3.4.1.js"></script>
<script type="text/javascript">
$(function(){
//1. 书写显示广告的定时器操作
time = setInterval("showAd()",3000);
});
//2. 书写显示广告图片的函数
function showAd(){
// 3.获取广告图片,并让其显示
// $("#img2").show(500); //普通样式
// $("#img2").slideDown(1000); //向下滑入
$("#img2").fadeIn(500); //渐入
// 4.清除显示图片定时操作
clearInterval(time);
// 5.设置隐藏图片的定时操作
time = setInterval("hiddenAd()",3000);
}
function hiddenAd(){
// 6.获取广告图片,隐藏
// $("#img2").hide(); //普通样式
// $("#img2").slideUp(1000); //向上滑出
$("#img2").fadeOut(500);
// 7.清除隐藏图片的定时操作
clearInterval(time);
}
</script>
————————————————
版权声明:本文为CSDN博主「艾诺_Aynor」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_40922845/article/details/102612693
全部代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>首页</title>
<style type="text/css">
#father {
border: 1px solid red;
width: 1250px;
height: 1550px;
/* 外边距 */
margin: auto;
}
#logo{
border: 1px solid blue;
width: 1250px;
height: 50px;
}
.top{
border: 1px solid gold;
width: 413px;
height: 50px;
float: left;
}
#menu{
border: 1px solid blue;
width: 1250px;
height: 50px;
background-color: #000000;
margin-bottom: 10px;
}
ul li{
display: inline;
color: white;
}
#product{
border: 1px solid yellow;
width: 1250px;
height: 560px;
}
#product_top{
border: 1px solid blue;
width: 100%;
height: 50px;
}
#product_bottom{
border: 1px solid black;
width: 100%;
height: 500px;
}
#product_bottom_left{
border: 1px solid pink;
width: 200px;
height: 500px;
float: left;
}
#product_bottom_right{
border: 1px solid cadetblue;
width: 1045px;
height: 500px;
float: left;
}
#big{
border: 1px solid black;
width: 520px;
height: 250px;
float: left;
}
.small{
border: 1px solid red;
width: 172px;
height: 250px;
float: left;
text-align: center;
}
/* 清除超链接的下划线 */
a{
text-decoration: none;
}
</style>
<script type="text/javascript" src="../js/jquery-3.4.1.js"></script>
<script type="text/javascript">
$(function(){
//1. 书写显示广告的定时器操作
time = setInterval("showAd()",3000);
});
//2. 书写显示广告图片的函数
function showAd(){
// 3.获取广告图片,并让其显示
// $("#img2").show(500); //普通样式
// $("#img2").slideDown(1000); //向下滑入
$("#img2").fadeIn(500); //渐入
// 4.清除显示图片定时操作
clearInterval(time);
// 5.设置隐藏图片的定时操作
time = setInterval("hiddenAd()",3000);
}
function hiddenAd(){
// 6.获取广告图片,隐藏
// $("#img2").hide(); //普通样式
// $("#img2").slideUp(1000); //向上滑出
$("#img2").fadeOut(500);
// 7.清除隐藏图片的定时操作
clearInterval(time);
}
</script>
</head>
<body onload="init()">
<div id="father">
<!-- 定时广告弹出位置 -->
<img id="img2" src="../img/合照合照.png" width="100%" style="display: none;">
<!-- Logo -->
<div id="logo">
<div class="top">
<img src="../img/艾诺重工Logo.png" height="46px" >
</div>
<div class="top">
<div class="top">
<img src="../img/艾诺重工Logo.png" height="46px" >
</div>
</div>
<div class="top">
<a href="#">登陆</a>
<a href="#">购物车</a>
<a href="#">登陆</a>
</div>
</div>
<!-- 导航栏 -->
<div id="menu">
<ul>
<a href="#"><li style="font-size: 20px;">首页</li></a>
<a href="#"><li>商品</li></a>
<a href="#"><li>商品</li></a>
<a href="#"><li>商品</li></a>
<a href="#"><li>商品</li></a>
<a href="#"><li>商品</li></a>
</ul>
</div>
<!-- 轮播图 -->
<div id="" style="text-align: center;">
<img src="../img/艾诺重工Logo.png" id="img1">
</div>
<!-- 最新商品 -->
<div id="product">
<div id="product_top" style="padding-left: 20px; padding-bottom: 25px;">
<span style="font-size: 25px;">最新商品 <img src="../img/艾诺重工Logo.png" ></span>
</div>
<div id="product_bottom">
<div id="product_bottom_left">
</div>
<div id="product_bottom_right">
<div id="big">
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
</div>
</div>
</div>
<!-- 广告 -->
<div id="" style="text-align: center;">
<img src="../img/艾诺重工Logo.png" >
</div>
<!-- 热门商品 -->
<div id="product">
<div id="product_top" style="padding-left: 20px; padding-bottom: 25px;">
<span style="font-size: 25px;">最新商品 <img src="../img/艾诺重工Logo.png" ></span>
</div>
<div id="product_bottom">
<div id="product_bottom_left">
</div>
<div id="product_bottom_right">
<div id="big">
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
<div class="small">
<img src="../img/艾诺重工Logo.png" >
<a href="#"><br><br><br><p style="color: black;">商品</p><p style="font-size: 15px;">¥199</p> </a>
</div>
</div>
</div>
</div>
<!-- 广告 -->
<div id="" style="text-align: center;">
<img src="../img/艾诺重工Logo.png" >
</div>
<!-- </div>友情链接 -->
<div id="" style="text-align: center">
<p>
<a href="https://www.ww-pass.com/">万物通行官网</a>
<a href="#">MOFUMOFU手作</a>
<a href="#">空格科技</a>
</p>
<p>
<a href="#">关于我们</a>
<a href="#">联系我们</a>
<a href="#">更多产品</a>
</p>
</div>
</div>
</body>
</html>
<!-- <script>
function init(){
//书写轮播图显示的定时操作
window.setInterval("changeImg()",3000);
}
// 书写函数
var flag = 0;
function changeImg(){
flag++;
if(flag==1){
document.getElementById("img2").src="../img/艾诺设定.png"
}
if(flag==2){
flag = 0;
document.getElementById("img2").src="../img/照相.png"
}
}
</script> -->
<!-- <script type="text/javascript">
function init(){
setInterval("changeImg()",3000);
}
var flag1 = 0;
function changeImg(){
flag++;
if(flag1==1){
document.getElementById("img1").src="../../img/艾诺设定.png"
}
if(flag1==2){
flag = 0;
document.getElementById("img1").src="../../img/照相.png"
}
}
</script> -->
<!-- <script type="text/javascript">
function init(){
// 1.设置显示广告图片的定时操作
time = setInterval("showAd()",3000);
}
// 2.书写显示广告图片的函数/
function showAd(){
// 3.获取广告图片的位置
var adEle = document.getElementById("img2");
// 4.修改广告图片元素里面的属性让其显示
adEle.style.display = "block";
// 5.清除显示图片的定时操作 不让其每3秒运行一次显示图片的函数
clearInterval(time);
//6.设置隐藏图片的定时操作
time = setInterval("hiddenAd()",3000);
}
// 7.书写隐藏广告图片的函数
function hiddenAd(){
//8.获取广告图片并设置其Style属性的display值为none
document.getElementById("img2").style.display="none";
//9.清除隐藏广告图片的定时操作 不让其每3秒运行一次隐藏图片的函数
clearInterval(time);
}
</script> -->