不给下面递增值为什么
//封装一个代替getElementById()的方法
function byId(id){
return typeof(id)==="string"?document.getElementById():id; //判断类型为id 三等号判断id值得时候判断类型如果 他是字符串 三元操作符
}
//全局变量
var index=0,
timer=null; //加定时器
function slideImg(){
var main=byId("main");
//滑过清除定时器,离开继续
main.onmouseover=function(){
//滑过清除定时器
}
main.onmouseout=function(){
timer=setInterval(function(){
index++;
console.log(index);
},3000);
}
}
正在回答 回答被采纳积分+1
<div class="main" id="main">
<!--图片轮播-->
<div class="banner">
<a href="#">
<div class="banner_slide slide1 slide-active "></div>
</a>
<a href="#">
<div class="banner_slide slide2"></div>
</a>
<a href="#">
<div class="banner_slide slide3"></div>
</a>
</div>
<!--上一张、下一张按钮-->
<a href="javascript:void(0)" class="button prev"></a> <!--意思是A标签不做任何跳转javascript:void(0)-->
<a href="javascript:void(0)" class="button next"></a> <!--意思是A标签不做任何跳转javascript:void(0)-->
<!--圆点导航-->
/<div class="dots">
<span class="active"></span>
<span></span>
<span></span>
</div>
</div>
css样式
/*banner主体开始*/
.banner{
width:1200px;
height:460px;
overflow:hidden; /*1.显示/2.隐藏*/
position:relative; /*相对定位*/
}
/*设置图片大小*/
.banner_slide{
width:1200px;
height:460px;
position:absolute; /*绝对定位*/
background-repeat:no-repeat; /*图片不重复显示*/
display:none; /*隐藏*/
}
.slide-active{
display:block;
}
/*轮播图片开始*/
.slide1{
background-image:url(../img/bg1.jpg) ;
}
.slide2{
background-image:url(../img/bg2.jpg) ;
}
.slide3{
background-image:url(../img/bg3.jpg) ;
}
//封装一个代替getElementById()的方法
function byId(id){
return typeof(id)==="string"?document.getElementById(id):id; //判断类型为id 三等号判断id值得时候判断类型如果 他是字符串 三元操作符
}
//全局变量
var index=0,
timer=null; //加定时器
pics=byId("banner").getElementsByTagName("div");
len=pics.length;
function slideImg(){
var main=byId("main");
//滑过清除定时器,离开继续
main.onmouseover=function(){
//滑过清除定时器
}
main.onmouseout=function(){
timer=setInterval(function(){
index++;
console.log(index);
if(index>=len){
index=0;
}
},2000);
}
}
slideImg();
script.js:8 Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
at script.js:8
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36712 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星