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
| var banner = document.querySelector('.banner'); var lb = document.querySelector('.left_button'); var rb = document.querySelector('.right_button'); var img = document.querySelector('.img'); var steta_ul = document.querySelector('.steta').querySelector('ul');
var num = 0;
var img_ul = img.querySelector('ul');
var img_li_wdith = img_ul.children[0].offsetWidth;
banner.addEventListener('mouseenter', function() { lb.style.display = 'block'; rb.style.display = 'block'; clearInterval(timer); timer = null; })
banner.addEventListener('mouseleave', function() { lb.style.display = 'none'; rb.style.display = 'none'; timer = setInterval(function () { rb.click(); }, 2000); })
for (var i = 0; i < img_ul.children.length; i++) { var li = document.createElement('li'); li.setAttribute('index', i) steta_ul.appendChild(li); li.addEventListener('click', function(){ for (var j = 0; j < steta_ul.children.length; j++) { steta_ul.children[j].className = ''; } this.className = 'colorr';
var index = this.getAttribute('index'); num = index; animate(img, -img_li_wdith * index) }) }
steta_ul.children[0].className = 'colorr';
var clone_li = img_ul.children[0].cloneNode(true); img.querySelector('ul').appendChild(clone_li);
var flag = true;
rb.addEventListener('click', function () { if (flag) { flag = false; if (num == img_ul.children.length - 1) { img.style.left = 0 + 'px'; num = 0; } num++; animate(img, -img_li_wdith * num, function () { flag = true; }); circleChange();
} })
lb.addEventListener('click', function () { if (flag){ flag = false; if (num == 0) { num = img_ul.children.length - 1; img.style.left = -img_li_wdith * (img_ul.children.length - 1) + 'px'; } num--; animate(img, -img_li_wdith * num, function(){ flag = true; }); circleChange(); } })
var timer = setInterval(function (){ rb.click(); },2000)
function circleChange() { for (var j = 0; j < steta_ul.children.length; j++) { steta_ul.children[j].className = ''; } if (num === img_ul.children.length - 1) { steta_ul.children[0].className = 'colorr'; } else { steta_ul.children[num].className = 'colorr'; } }
function animate(obj, target, callback) { clearInterval(obj.timer); obj.timer = setInterval(function() { var step = (target - obj.offsetLeft) / 10; step = step > 0 ? Math.ceil(step) : Math.floor(step); if (obj.offsetLeft == target) { clearInterval(obj.timer); callback && callback(); } obj.style.left = obj.offsetLeft + step + 'px'; }, 15); }
|