美文网首页
10.1 无缝轮播 图片是float left 注意与 网易

10.1 无缝轮播 图片是float left 注意与 网易

作者: 康轩 | 来源:发表于2017-06-05 17:29 被阅读0次

1 添加第一张图片 oUl.appenChild(lis[0].cloneNode(true))
2.for.遍历 创建li
3.oLi.appendChild(li)
4.给 li 中的第一个 ol 添加类名
5.,for 遍历 排他思想 设置 ol
6 用更新ol 的索引的对应的ul中的li一起滚动
7 调用封装好的匀速动画的框架
8 contan(obj.target.speed)
<script src="myFn.js"></script>
<script>
window.onload = function () {
// alert(0)
var all = document.getElementById('all');
var top = document.getElementById('top');
var oul = document.getElementById('oul');
var ol = document.getElementById('ol');
var lis = oul.children;
var bigIndex = 0;
var smallIndex = 0;
// var timer = null;
//那么我们首先是先添加一张图片放在最后面 而这张图片的第一张

    oul.appendChild(lis[0].cloneNode(true));
   // console.log(oul.children.length);    //6
    //
    for (var i = 0; i < lis.length - 1; i++) {
        //添加小圆点 这里 添加的不只是一个ol li 的一个点  而是一整排里面的5个小圆点 因为for 遍历的是oul中里的个数
      var oli=document.createElement('li');
        ol.appendChild(oli);//这行注意小括号里面不能有冒号

// console.log(ol.children.length); //5
}
ol.children[0].className = 'curr';
//让 移动到小圆点的时候 让对应的小圆点的颜色为red
for (var i = 0; i < ol.children.length; i++) {
ol.children[i].index = i;

        ol.children[i].onmouseover = function () {
            for (var i = 0; i < ol.children.length; i++) {
                ol.children[i].className= '';
            }
            ol.children[this.index].className = 'curr';
            constant(oul,20,-this.index*750);

// oulIndex = this.index;
// smallIndex = this.index;
// oulIndex = smallIndex = this.index;
}
}
//自动起来
var timer = setInterval(autoPlay,1000);
function autoPlay() {
bigIndex ++;
if (bigIndex> lis.length - 1) {
bigIndex = 1;
oul.style.left = 0 + 'px';
}
constant(oul,20,-bigIndex * 750);
smallIndex ++;
if (smallIndex > ol.children.length - 1) {
smallIndex = 0;
}
for (var i = 0; i < ol.children.length; i++) {
ol.children[i].className = '';
}
ol.children[smallIndex].className = 'curr';
}
}
</script>

相关文章

  • 10.1 无缝轮播 图片是float left 注意与 网易

    1 添加第一张图片 oUl.appenChild(lis[0].cloneNode(true))2.for.遍历 ...

  • 14_JS轮播图案例

    仿网易轮播图 初始状态,第一张图片在盒子中间,其他图片在右边imgs[i].style.left = 盒子宽度+"...

  • clearfix

    css中float left与float right的使用说明

  • 实现两列布局的方法

    html 1. float+margin-left left设为float: left,脱离文档流。right是块...

  • task31 进阶:把轮播改成无缝轮播吧

    1. 无缝的轮播怎么做 什么是无缝轮播? 从第一张到倒数第二张图片还好,但是从最后一张图片到第一张图片就有问题了,...

  • CSS布局小结

    左右布局 可使用float来实现,对左部分区域float:left,对右部分区域float:right,注意在其父...

  • 图片

    1 图片库 div { text-align: center; float: left; margin: 2...

  • 轮播

    无缝轮播 css需要让图片或者文本水平排列,overflow:hidden隐藏其他图片 整体图片向左/右偏移,就会...

  • 左不定宽,右自适应

    利用float+overflow实现 .left{float:left;}.right{overflow:hidd...

  • CSS:两栏布局

    1.直接float:left; 2.absolute+margin-left; 3.使用float:left+ma...

网友评论

      本文标题:10.1 无缝轮播 图片是float left 注意与 网易

      本文链接:https://www.haomeiwen.com/subject/towsfxtx.html