index.html 页面展示代码
Home Web Front-end JS Tutorial JS slideshow can be looped and rotated smoothly with scrolling navigation (self-written)_javascript skills

JS slideshow can be looped and rotated smoothly with scrolling navigation (self-written)_javascript skills

May 16, 2016 pm 05:26 PM
Loop

Recently, I was helping others change something. I searched online for a long time, but there was nothing the same. I changed it myself and shared it:
First, let’s show the effect:
JS slideshow can be looped and rotated smoothly with scrolling navigation (self-written)_javascript skills
index.html Page display code

Copy code The code is as follows:







< ;SCRIPT language="JavaScript" src="js/16sucai.js">

< ;/head>







  • Xiao Qiao, one of the main female figures during the Three Kingdoms period. During the Three Kingdoms period, she belonged to the Wu State. She was a beautiful woman with extraordinary talents and beauty. She was a famous Soochow beauty at that time.




  • Pan An, a writer in the Western Jin Dynasty, whose real name is Pan Yue. The most famous handsome man in ancient China and the first of the "Twenty-Four Friends of the Golden Valley".




  • Zhu Yuanzhang, the founding emperor of the Ming Dynasty, established a unified feudal regime across the country.




  • Lu Fei, the first wife of Liu Bang, the founding emperor of the Western Han Dynasty, was the first female ruler to hold power in Chinese history.




  • Zhuge Liang, Prime Minister of the Shu Han Dynasty, was an outstanding statesman, strategist, inventor, and military strategist during the Three Kingdoms period.







< label name='numBut' id='2'>






< ;/html>

The following is the corresponding JS file content:
Copy code The code is as follows :

//var tempi=0;
function ZoomPic ()
{
this.initialize.apply(this, arguments);
}
ZoomPic.prototype =
{
initialize : function (id)
{
var _this = this;
this.wrap = typeof id === "string" ? document.getElementById(id) : id;
this.oUl = this.wrap.getElementsByTagName("ul")[0];
this.aLi = this.wrap.getElementsByTagName("li");
this.spans = this.wrap.getElementsByTagName("label");
this.prev = this.wrap.getElementsByTagName("pre")[0];
this.next = this.wrap.getElementsByTagName("pre")[1];
this.timer = null;
this.aSort = [];
this.aSpan = [];
this.iCenter = 2;
this._doPrev = function () {return _this.doPrev.apply(_this)};
this._doNext = function () {return _this.doNext.apply(_this)};
this.options = [
{width:50, height:212, top:55, left:0, zIndex:1},
{width:90, height:252, top:35, left:50, zIndex:2},
{width:400, height:292, top:10, left:140, zIndex:3},
{width:90, height:252, top:35, left:540, zIndex:2},
{width:50, height:212, top:55, left:630, zIndex:1}
];
for (var i = 0; i < this.aLi.length; i ) this.aSort[i] = this.aLi[i];
for (var i = 0; i < this.spans.length; i ) this.aSpan[i] = this.spans[i];
this.aSort.unshift(this.aSort.pop());
this.setUp();
this.addEvent(this.prev, "click", this._doPrev);
this.addEvent(this.next, "click", this._doNext);
this.doImgClick();
this.dospansClick();
this.timer = setInterval(function ()
{
_this.doNext()
}, 3000);
this.wrap.onmouseover = function ()
{
clearInterval(_this.timer)
};
this.wrap.onmouseout = function ()
{
_this.timer = setInterval(function ()
{
_this.doNext()
}, 3000);
}
},
doPrev : function ()
{
this.aSort.unshift(this.aSort.pop());//删除数组最后一项,并且返回数组 获取最后一位
this.setUp()
},
doNext : function ()
{
this.aSort.push(this.aSort.shift());//删除数组第一项,并且返回数组 删除第一位,然后把第一位push到最后一个上面
this.setUp()
},
doImgClick : function ()
{
var _this = this;
for (var i = 0; i < this.aSort.length; i )
{
this.aSort[i].onclick = function ()
{ //alert(this.index);
if (this.index > _this.iCenter)
{
for (var i = 0; i < this.index - _this.iCenter; i ) _this.aSort.push(_this.aSort.shift());
_this.setUp()
}
else if(this.index < _this.iCenter)
{
for (var i = 0; i < _this.iCenter - this.index; i ) _this.aSort.unshift(_this.aSort.pop());
_this.setUp()
}
}
}
},dospansClick:function(){
var _this = this;
for (var i = 0; i < this.aSpan.length; i )
{
this.aSpan[i].onclick = function ()
{
//alert(this.id);
//alert(_this.aSort[_this.iCenter].getElementsByTagName('img')[0].name);//获取到当前是第几个在中间
var cruuNum=_this.aSort[_this.iCenter].getElementsByTagName('img')[0].name;
// if (this.id > _this.iCenter)
// {
// for (var i = 0; i < this.id - _this.iCenter; i ) _this.aSort.push(_this.aSort.shift());//取
// _this.setUp()
//alert(this.id '...' cruuNum);
if(this.id-cruuNum>0){
for (var i = 0; i < this.id-cruuNum; i ) _this.aSort.push(_this.aSort.shift());//取
_this.setUp()
}else{
//if(cruuNum==5){
//if(this.id-cruuNum>0){
for (var i = 0; i < -(this.id-cruuNum); i ) _this.aSort.unshift(_this.aSort.pop());//取
_this.setUp();
//}

//}
}
// else{
// for (var i = 0; i < -(this.id-cruuNum); i ) _this.aSort.push(_this.aSort.shift());//取
// _this.setUp()
//
// }




// }
// else if(this.id < _this.iCenter)
// {
// for (var i = 0; i < _this.iCenter - this.id; i ) _this.aSort.unshift(_this.aSort.pop());
// _this.setUp()
// }

// for (var i = 0; i <5; i ){
// _this.aSort.push(_this.aSort.shift());//取第一个
// alert(_this.aSort[_this.iCenter].getElementsByTagName('img')[0].name 'aaa' this.id);
// if(_this.aSort[_this.iCenter].getElementsByTagName('img')[0].name==(this.id 1)){
// _this.setUp()
// break;
// }
// }

}
}
},
setUp : function ()
{
var _this = this;
var i = 0;
for (i = 0; i < this.aSort.length; i ) this.oUl.appendChild(this.aSort[i]);//gebytagui0
for (i = 0; i < this.aSort.length; i )
{
this.aSort[i].index = i;
//控制浮动层
if (i < 5)
{

this.css(this.aSort[i], "display", "block");
this.doMove(this.aSort[i], this.options[i], function ()
{
_this.doMove(_this.aSort[_this.iCenter].getElementsByTagName("img")[0], {opacity:100}, function ()
{
_this.doMove(_this.aSort[_this.iCenter].getElementsByTagName("img")[0], {opacity:100}, function ()
{
_this.aSort[_this.iCenter].onmouseover = function ()//鼠标放上去
{
_this.doMove(this.getElementsByTagName("div")[0], {bottom:0})
};
_this.aSort[_this.iCenter].onmouseout = function ()
{
_this.doMove(this.getElementsByTagName("div")[0], {bottom:-100})
}
})
})
});
}
else
{
this.css(this.aSort[i], "display", "none");
this.css(this.aSort[i], "width", 0);
this.css(this.aSort[i], "height", 0);
this.css(this.aSort[i], "top", 37);
this.css(this.aSort[i], "left", this.oUl.offsetWidth / 2)
}
if (i < this.iCenter || i > this.iCenter)//
{
this.css(this.aSort[i].getElementsByTagName("img")[0], "opacity", 30)
this.aSort[i].onmouseover = function ()
{
_this.doMove(this.getElementsByTagName("img")[0], {opacity:100})
};
this.aSort[i].onmouseout = function ()
{
_this.doMove(this.getElementsByTagName("img")[0], {opacity:35})
};
this.aSort[i].onmouseout();
}
else
{
//中间 一直是2
//alert(this.aSort[i].text);//取消变亮事件
//alert(this.aSort[i].getElementsByTagName("img")[0].name);
//变换颜色
var ttSe=this.aSort[i].getElementsByTagName("img")[0].name;
var numbuts= document.getElementsByName('numBut');
//alert(numbuts.length);

for(var t=0;tif(t==0){
if(ttSe==5){
numbuts[t].className ='numbutLeftCen';
}else
numbuts[t].className ='numbutLeft';
}else if(t==ttSe){
numbuts[t].className ='numbutCen';
}else if(t==numbuts.length){
//alert(t);
numbuts[0].className ='numbutCen';
}else{
//全部修改class
numbuts[t].className='numbut';
}
//var aObj = document.getElementById("a的ID");
//添加事件
//alert(tempi);
// if(tempi==0){//alert(tempi);
// if (window.addEventListener) {//Mozilla系列
// numbuts[t].addEventListener('click', _this.addClick(t 1), false);
// } else if (window.attachEvent) {//IE
// numbuts[t].attachEvent('onclick', this.addClick(t 1));
// }
// }
}
//tempi ;
this.aSort[i].onmouseover = this.aSort[i].onmouseout = null
}
}
},addEvent : function (oElement, sEventType, fnHandler)
{
return oElement.addEventListener ? oElement.addEventListener(sEventType, fnHandler, false) : oElement.attachEvent("on" sEventType, fnHandler)
},
css : function (oElement, attr, value)
{
if (arguments.length == 2)
{
return oElement.currentStyle ? oElement.currentStyle[attr] : getComputedStyle(oElement, null)[attr]
}
else if (arguments.length == 3)
{
switch (attr)
{
case "width":
case "height":
case "top":
case "left":
case "bottom":
oElement.style[attr] = value "px";
break;
case "opacity" :
oElement.style.filter = "alpha(opacity=" value ")";
oElement.style.opacity = value / 100;
break;
default :
oElement.style[attr] = value;
break
}
}
},
doMove : function (oElement, oAttr, fnCallBack)
{
var _this = this;
clearInterval(oElement.timer);
oElement.timer = setInterval(function ()
{
var bStop = true;
for (var property in oAttr)
{
var iCur = parseFloat(_this.css(oElement, property));
property == "opacity" && (iCur = parseInt(iCur.toFixed(2) * 100));
var iSpeed = (oAttr[property] - iCur) / 5;
iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);

if (iCur != oAttr[property])
{
bStop = false;
_this.css(oElement, property, iCur iSpeed)
}
}
if (bStop)
{
clearInterval(oElement.timer);
fnCallBack && fnCallBack.apply(_this, arguments)
}
}, 30)
},addClick:function (num){
//alert(num);
// if (this.index > _this.iCenter)
// {
// for (var i = 0; i < this.index - _this.iCenter; i ) _this.aSort.push(_this.aSort.shift());
// _this.setUp()
// }
}
};
window.onload = function ()
{
new ZoomPic("box");
};
function tt(){
//alert(1);

}

OK,最后加上一些样式上的东西,就可以跑起来了;
复制代码 代码如下:

body {
margin: 0px; padding: 0px;
}
div {
margin: 0px; padding: 0px;
}
ul {
margin: 0px; padding: 0px;
}
li {
margin: 0px; padding: 0px;
}
h4 {
margin: 0px; padding: 0px;
}
p {
margin: 0px; padding: 0px;
}
body {
no-repeat 50% 0px rgb(0, 0, 0); font: 12px/1.8 arial; color: rgb(255, 255, 255); font-size-adjust: none; font-stretch: normal;
}
a {
background: rgb(102, 102, 102); padding: 2px 5px; color: rgb(255, 255, 255); text-decoration: none;
}
a:hover {
background: rgb(255, 153, 0);
}
#box {
margin: 1px auto 0px; width: 680px; height: 320px; position: relative;
}
#box ul {
width: 680px; height: 320px; position: relative;
}
#box li {
background: rgb(0, 0, 0); list-style: none; border-radius: 3px; border:0px solid rgb(0, 0, 0); left: 377px; top: 146px; width: 0px; height: 0px; overflow: hidden; position: absolute; z-index: 0; cursor: pointer;
}
#box li div {
background: rgb(0, 0, 0); width: 100%; height:40px; bottom: -100px; position: absolute; opacity: 0.7;
}
#box li div h4 {
font: 12px/24px arial; margin: 0px 10px; border-bottom-color: rgb(51, 51, 51); border-bottom-width: 1px; border-bottom-style: solid; font-size-adjust: none; font-stretch: normal;
}
#box li div h4 span {
color: red; margin-left: 10px;
}
#box li div p {
margin: 5px 10px 0px; text-indent: 2em;
}
.numbutLeft{width: 15px; height: 5px; background-color:#AFB7B6; float: left; cursor: pointer;}
.numbut{width: 15px; height: 5px; background-color:#AFB7B6; float: left; margin-left: 5px; cursor: pointer;}
.numbutCen{width: 15px; height: 5px; background-color:#FF0000; float: left; margin-left: 5px; cursor: pointer;}
.numbutLeftCen{width: 15px; height: 5px; background-color:#FF0000; float: left; cursor: pointer;}
.numbutdiv{height: 10px;width: 100%;color: red;margin-top: 0px; padding-top: 0px}
.ndv{height: 10px;width: 95px; margin: 0 auto}
#box .next {
background-position: -39px 0px; right: -60px;
}
#copyright {
text-align: center; padding-top: 10px;
}

OOOOOKKK 了,奇特的效果就要出来了 ,还有一些不完美的地方,懒得去改了,有高手可以改改看,但希望分享哦。
效果如下:
JS slideshow can be looped and rotated smoothly with scrolling navigation (self-written)_javascript skills
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if I encounter garbled code printing for front-end thermal paper receipts? What should I do if I encounter garbled code printing for front-end thermal paper receipts? Apr 04, 2025 pm 02:42 PM

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

Demystifying JavaScript: What It Does and Why It Matters Demystifying JavaScript: What It Does and Why It Matters Apr 09, 2025 am 12:07 AM

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

Who gets paid more Python or JavaScript? Who gets paid more Python or JavaScript? Apr 04, 2025 am 12:09 AM

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

How to merge array elements with the same ID into one object using JavaScript? How to merge array elements with the same ID into one object using JavaScript? Apr 04, 2025 pm 05:09 PM

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

Is JavaScript hard to learn? Is JavaScript hard to learn? Apr 03, 2025 am 12:20 AM

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

How to achieve parallax scrolling and element animation effects, like Shiseido's official website?
or:
How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? How to achieve parallax scrolling and element animation effects, like Shiseido's official website? or: How can we achieve the animation effect accompanied by page scrolling like Shiseido's official website? Apr 04, 2025 pm 05:36 PM

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

The Evolution of JavaScript: Current Trends and Future Prospects The Evolution of JavaScript: Current Trends and Future Prospects Apr 10, 2025 am 09:33 AM

The latest trends in JavaScript include the rise of TypeScript, the popularity of modern frameworks and libraries, and the application of WebAssembly. Future prospects cover more powerful type systems, the development of server-side JavaScript, the expansion of artificial intelligence and machine learning, and the potential of IoT and edge computing.

The difference in console.log output result: Why are the two calls different? The difference in console.log output result: Why are the two calls different? Apr 04, 2025 pm 05:12 PM

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

See all articles