課程
/前端開發(fā)
/JavaScript
/焦點(diǎn)圖輪播特效
為什么代碼和老師敲的一點(diǎn)擊箭頭圖片老是第一張
2016-10-18
源自:焦點(diǎn)圖輪播特效 3-1
正在回答
如果錯(cuò)誤都找出來(lái),證明你學(xué)會(huì)了,其它可以從別人的代碼中找錯(cuò)誤也是一種學(xué)習(xí)方法。
iyffvpigriqbarlqakdewmxfiymxiwovdtwwubmgynjjpcqwdiicbqsfsqlzsbrlezzxcfwaoebfylafeidsphyvolkchkdyjresyuhvsbkhvsuzffyxgmlxzxhli
window.onload=function ?() {
var container =document.getElementById("container");
var list=document.getElementById("list");
var buttons=document.getElementById("buttons").getElementsByTagName("span");
var prev=document.getElementById("prev");
var next=document.getElementById("next");
var index=1;
var animated =false;
function showb() {
for (var i = 0; i <buttons.length; i++) {
if (buttons[i].className=="on"){
buttons[i].className="";
break;
}
buttons[index -1].className ="on";
function animate(offset) {
animated=true;
var news=parseInt(list.style.left)+offset;
var time=300; ? //總時(shí)間
var interval =10; //間隔時(shí)間
var speed=offset/(time/interval);
function go() {
if ((speed < 0 && parseInt(list.style.left)>news) || ?(speed>0 && parseInt(list.style.left)<news)) {
list.style.left=parseInt(list.style.left)+speed+"px";
setTimeout(go,interval);
// statement
else{
animated=false;
list.style.left =news+"px";
if (news>-600) {
list.style.left=-3000+"px";
if (news<-3000 ){
list.style.left=-600+"px";
go();
next.onclick=function () {
if (index==5) {
index=1;
else {
index+=1;
showb();
if (!animated) {
animate(-600);
prev.onclick=function () {
if (index==1) {
index=5;
index-=1;
animate(600);
for (var i = 0; i < buttons.length; i++) {
? ? ? ? ? ? ? ? buttons[i].onclick = function () {
? ? ? ? ? ? ? ? ? ? if (animate) {
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if(this.className == 'on') {
? ? ? ? ? ? ? ? ? ? var myIndex = parseInt(this.getAttribute('index'));
? ? ? ? ? ? ? ? ? ? var offset = -600 * (myIndex - index);
? ? ? ? ? ? ? ? ? ? showb();
? ? ? ? ? ? ? ? ? ? if (!animated) {
? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? animate(offset);
? ? ? ? ? ? ? ? ? ? index = myIndex;
? ? ? ? ? ? ? ? }
舉報(bào)
通過(guò)本教程學(xué)習(xí)您將能掌握非常實(shí)用的焦點(diǎn)圖輪播特效的制作過(guò)程
1 回答輪番圖圖片100%
1 回答輪播圖無(wú)限滾動(dòng)問(wèn)題
2 回答怎么實(shí)現(xiàn)全屏banner的輪播圖
1 回答漸變的輪播圖怎么實(shí)現(xiàn)呢?
3 回答關(guān)于輪播圖按鈕事件的問(wèn)題
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2022-03-29
如果錯(cuò)誤都找出來(lái),證明你學(xué)會(huì)了,其它可以從別人的代碼中找錯(cuò)誤也是一種學(xué)習(xí)方法。
iyffvpigriqbarlqakdewmxfiymxiwovdtwwubmgynjjpcqwdiicbqsfsqlzsbrlezzxcfwaoebfylafeidsphyvolkchkdyjresyuhvsbkhvsuzffyxgmlxzxhli
2016-10-18
window.onload=function ?() {
var container =document.getElementById("container");
var list=document.getElementById("list");
var buttons=document.getElementById("buttons").getElementsByTagName("span");
var prev=document.getElementById("prev");
var next=document.getElementById("next");
var index=1;
var animated =false;
function showb() {
for (var i = 0; i <buttons.length; i++) {
if (buttons[i].className=="on"){
buttons[i].className="";
break;
}
}
buttons[index -1].className ="on";
}
function animate(offset) {
animated=true;
var news=parseInt(list.style.left)+offset;
var time=300; ? //總時(shí)間
var interval =10; //間隔時(shí)間
var speed=offset/(time/interval);
function go() {
if ((speed < 0 && parseInt(list.style.left)>news) || ?(speed>0 && parseInt(list.style.left)<news)) {
list.style.left=parseInt(list.style.left)+speed+"px";
setTimeout(go,interval);
// statement
}
else{
animated=false;
list.style.left =news+"px";
if (news>-600) {
list.style.left=-3000+"px";
}
if (news<-3000 ){
list.style.left=-600+"px";
}
}
}
go();
}
next.onclick=function () {
if (index==5) {
index=1;
}
else {
index+=1;
}
showb();
if (!animated) {
animate(-600);
}
}
prev.onclick=function () {
if (index==1) {
index=5;
}
else {
index-=1;
}
showb();
if (!animated) {
animate(600);
}
}
for (var i = 0; i < buttons.length; i++) {
? ? ? ? ? ? ? ? buttons[i].onclick = function () {
? ? ? ? ? ? ? ? ? ? if (animate) {
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? if(this.className == 'on') {
? ? ? ? ? ? ? ? ? ? ? ? return;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? var myIndex = parseInt(this.getAttribute('index'));
? ? ? ? ? ? ? ? ? ? var offset = -600 * (myIndex - index);
? ? ? ? ? ? ? ? ? ? showb();
? ? ? ? ? ? ? ? ? ? if (!animated) {
? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? animate(offset);
? ? ? ? ? ? ? ? ? ? index = myIndex;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? }
}
}