为什么轮播后图片覆盖在了当前区域其他元素上面?

为什么轮播后图片覆盖在了当前区域其他元素上面?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html>
<head>
        <meta charset="UTF-8">
        <title>Welcome Dodo!</title>
        <link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
<!-- 头部 -->
<div class="header">
<div class="logo">
<img src="imgs/DoDo-logo.png" alt="logo"/>
</div>
<div class="nav">
<ul>
<li>DoDo之心</li>
<li>旅行杂记</li>
<li>DoDo之家</li>
<li>愿望清单</li>
</ul>
</div>
</div>
<!-- 主体 -->
<div class="main">
<!-- 图片 -->
<div class="top" id="top">
<a href="#">
<div class="top-slide slide1 slide-active">
<img src="imgs/首页头元素.jpg">
</div>
</a>
<a href="#">
<div class="top-slide slide2">
<img src="imgs/首页头元素2.jpg">
</div>
</a>
<a href="#">
<div class="top-slide slide3">
<img src="imgs/首页头元素3.jpg">
</div>
</a>
 
<!-- 前后改变图片按钮 -->
<a href="#" class="change prev"></a>
<a href="#" class="change next"></a>
 
<!-- 遮罩层 -->
<div class="toplayer"></div>
<div class="toplayer-top">
<div class="word">MY BEAUTIFUL LIFE</div>
<button>LOOK MORE &gt;</button>
</div>
<!-- 圆点提示图片位置按钮 -->
<div class="dots">
<span class="active"></span>
<span></span>
<span></span>
</div>
</div>
<!-- 主体中间部分 -->
<div class="middle">
<div class="m-top">
"I want to give good things to record down,<br> after the recall will be very beautiful."
</div>
<!-- 主体中间的图片 -->
<div class="m-bottom">
<div class="m-com">
<img src="imgs/mid-1.jpg">
<div class="desc1">达西庄园</div>
<div class="desc2">美好的下午茶时光</div>
</div>
<div class="m-com">
<img src="imgs/mid-2.jpg">
<div class="desc1">卡里克索桥</div>
<div class="desc2">漫步海边的悬崖索桥</div>
</div>
<div class="m-com">
<img src="imgs/mid-3.jpg">
<div class="desc1">我的学校</div>
<div class="desc2">在天台享受谢菲美景</div>
</div>
</div>
</div>
<div class="bottom">
<div class="content">
<div class="title">
FROM THE PHOTO ALBUM
</div>
<div class="mix">
<dl>
<dt><img src="imgs/book.jpg"></dt>
<dd class="word">
Life is like a book, just read more and more refined, more write more carefully. When read, mind open, all things have been indifferent to heart. Life is the precipitation.
</dd>
</dl>
<dl>
<dt><img src="imgs/afternoonTea.jpg"></dt>
<dd class="word">
Life is like a cup of tea, let people lead a person to endless aftertastes. You again good taste, it will always have a different taste, different people will have different taste more.
</dd>
</dl>
</div>
</div>
</div>
</div>
<!-- 底部 -->
<div class="footer">
© 2019 DoDo跨国宣传部总负责 欢迎联系^_^
</div>
<script type="text/javascript" src="js/script.js"></script>
</body>
</html>
 
 
function byID( id ){
    return typeof(id) === "string"? document.getElementById(id) : id;
}
 
var index = 0, timer = null, pics = byID("top").getElementsByTagName("div")
    len = pics.length;
 
 
function slideImg(){
    var top = byID("top");
    //划过清除定时器
    top.onmouseover = function(){
 
    }
 
    //鼠标移走开始定时器
    top.onmouseout = function(){
        timer = setInterval(function(){
            index = (index+4)%3;
            //切换图片
            console.log(index);
            changeImg();
        }, 5000);
 
    }
     
}
 
 
function changeImg(){
    for(var i = 0; i < len; i++){
        pics[i].style.display = "none";
    }
    pics[index].style.display = 'inline';
 
}
 
slideImg();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
*{
    padding0;
    margin0;
}
 
ul{
    list-stylenone;
}
 
@font-face{
    font-family'Special';
    srcurl('font/dodo1.ttf'format("truetype");
}
 
.header{
    width100%;
    height100px;
    overflowhidden;
}
 
.header img{
    height100px;
    padding-left130px;
}
 
.header .logo{
    floatleft;
}
 
.header .nav{
    floatright;
    overflowhidden;
}
 
.header .nav ul {
    padding-right100px;
}
 
.header .nav ul li{
    list-stylenone;
    floatleft;
    width130px;
    height100px;
    line-height100px;
    font-size18px;
    font-weightbolder;
    colorgray;
}
 
.main .top{
    width100%;
    height400px;
    overflowhidden;
    positionrelative;
}
 
.main .top .top-slide{
    width100%;
    height400px;
    background-repeatno-repeat;
    positionabsolute;
    displaynone;
    z-index-1;
}
 
.main .top .slide-active{
    display:block;
}
 
.main .top .top-slide img{
    width100%;
    height400px;
}
 
.main{
    positionrelative;
}
 
.main .change{
    positionabsolute;
    width40px;
    height80px;
    top160px;
    backgroundurl(../imgs/arrow.png) no-repeat center center;
    z-index3;
 
}
 
 
 
.main .change:hover{
    background-color#333;
    opacity: 0.3;
    filter: alpha(opacity=30);
}
 
.main .prev{
    transform: rotate(180deg);
}
 
.main .next{
    right0;
}
 
.main .toplayer{
    positionabsolute;
    top0px;
    left0px;
    background-color#000;
    width100%;
    height400px;
    opacity: 0.5;
    z-index1;
}
 
.main .dots{
    positionabsolute;
    right25px;
    top355px;
    text-alignright;
    z-index10;
 
}
 
.main .dots span{
    display: inline-block;
    width12px;
    height12px;
    line-height12px;
    border-radius: 50%;
    background: rgba(7,17,270.2);
    box-shadow: 0 0 0 2px rgba(2552552550.6inset;
    margin-left8px;
    cursorpointer;
 
}
 
.main .dots .active{
    box-shadow: 0 0 0 2px rgba(7,17,270.8inset;
    background-color#fff;
}
 
.main .toplayer-top{
    positionabsolute;
    top200px;
    left50%;
    width500px;
    height200px;
    margin-top-100px;
    z-index2;
    margin-left-250px;
}
 
.main .toplayer-top .word{
    padding-top30px;
    padding-bottom20px;
    color#fff;
    font-size40px;
    font-weightbolder;
    text-aligncenter;
    font-family"微软雅黑";
}
 
.main .toplayer-top button{
    width200px;
    height60px;
 
    margin-top30px;
    color#fff;
    text-aligncenter;
    font-family"微软雅黑";
    background-color#6495ED;
    font-size14px;
    font-weightbolder;
    border-radius: 8px;
    margin-left150px;
}
 
.main .middle{
    width1000px;
    margin:0 auto;
}
 
.main .middle .m-top{
    font-size26px;
    color#D2B4DE;
    padding-top50px;
    font-styleitalic;
    text-aligncenter;;
    padding-bottom50px;
    font-family"Times New Roman";
}
 
.main .middle .m-bottom{
    overflowhidden;
}
 
.main .middle .m-bottom .m-com{
    floatleft;
    padding10px;
    text-aligncenter;
    font-weightbolder;
}
 
.main .middle .m-bottom .m-com img{
    width300px;
    height300px;
}
 
.main .middle .m-bottom .m-com .desc1{
    font-size20px;  
    color#7D7D7F;
    margin-top20px;
}
 
.main .middle .m-bottom .m-com .desc2{
    font-size18px;
    color#BDBDBC;
    margin-top10px;
    text-aligncenter;
}
 
.main .bottom{
    background-color#EAEDED;
}
 
.main .bottom .content{
    width1000px;
    margin:0 auto;
    text-aligncenter;
}
 
.main .bottom .content .title{
    font-size23px;
    font-weightbold;
    color#7D7C7F;
    padding-top50px;
 
}
 
.main .bottom .content .mix{
    overflowhidden;
}
 
.main .bottom .content .mix dl{
    floatleft;
    width450px;
    padding20px;
    padding-top40px;
     
}
 
.main .bottom .content .mix img{
    width400px;
}
 
.main .bottom .content .mix dl .word{
    font-family: Special;
    padding-top20px;
    font-size18px;
    font-weightbolder;
    color#7D7C7F;
    padding-bottom50px;
}
 
.footer{
    width100%;
    height100px;
    background-color#292C35;
    colorwhite;
    font-size15px;
    text-aligncenter;
    line-height100px;
}


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,同学是说图片轮播覆盖了主体部分的上边吗?因为同学将轮播的图片及样式也设置到主体的上边,所以轮播图片覆盖了MY BEAUTIFUL LIFE的元素。建议同学在主体上边再加一个div,使其作为图片轮播的区域,再给该区域设置图片及轮播样式。

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

  • 慕莱坞6206856 提问者 #1
    我自己解决了,是因为获取的元素是所有的div元素,所以我给需要更改的图片加了一个name属性,然后获取该类的元素就好了
    2019-01-18 21:33:11
  • 慕莱坞6206856 提问者 #2
    老师的解决方式也是对的,增加一个div单独涵盖轮播图片元素也可以解决。我应该注意输出调试数组的长度,之前没有关注这一点。哈哈哈,谢谢老师。
    2019-01-18 21:34:40
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
从网页搭建入门Java Web2018版
  • 参与学习           人
  • 提交作业       1088    份
  • 解答问题       10204    个

如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码