JS特效——轮播图

这篇博客展示了如何利用JavaScript实现一个简单的图片轮播效果。通过设置CSS样式和JavaScript事件监听,实现在鼠标悬停时停止轮播,离开时恢复自动切换。代码中详细解释了每个关键部分的作用,包括图片的堆叠、按钮的生成和点击事件处理,以及定时器的管理。
<!DOCTYPE html>
<html>

<head>
<title>新闻特效切换</title>
<meta charset="utf-8">
<style>
#slideshow-wrapper {
position: relative;
padding: 0;
background: #121212;
width: 650px;
height: 400px;
overflow: hidden;
}
#slideshow-footbar {
z-index: 5;
position: absolute;
opacity: 0.5;
width: 100%;
height: 30px;
background: black;
bottom: 0;
}
#slideshow-photo {
position: absolute;
width: 100%;
height: 100%;
cursor: pointer;
}
#slideshow-photo a {
z-index: 1;
position: absolute;
margin: 0;
top: 0;
left: 0;
display: block;
}
#slideshow-footbar .slideshow-bt {
background: #d2d3d4;
margin: 10px 10px 0 0;
width: 10px;
display: inline;
float: right;
height: 10px;
}
#slideshow-footbar .bt-on {
background: blue;
}
</style>
</head>

<body>
<div id="slideshow-wrapper">
<div id="slideshow-photo">
<a target="_blank" style="z-index: 2" href="#" index="1">
<img src="http://img.zcool.cn/community/013dad554ba7be000001bf72cc05bf.jpg@2o.jpg">
</a>
<a target="_blank" style="z-index: 1" href="#" index="2">
<img src="http://img.zcool.cn/community/010ab0554ba7bf000001bf72867e3b.jpg@2o.jpg">
</a>
<a target="_blank" style="z-index: 1" href="#" index="3">
<img src="http://img.zcool.cn/community/01b020558c032c0000003264de904a.jpg@2o.jpg">
</a>
<a target="_blank" style="z-index: 1" href="#" index="4">
<img src="http://img.zcool.cn/community/014872558c03b200000098b5bf3693.jpg@2o.jpg">
</a>
<a target="_blank" style="z-index: 1" href="#" index="5">
<img src="http://img.zcool.cn/community/01fb9558e49702a801219c77debb30.jpg@1280w_1l_2o_100sh.webp">
</a>
</div>
<div id="slideshow-footbar"></div>
</div>

<script>
window.onload = init;
let currIndex = 1;
let timer = null;
let wrapper = document.getElementById('slideshow-wrapper');
        // 鼠标移入移除事件
wrapper.onmouseover = function() {
clearInterval(timer);
}

wrapper.onmouseout = function() {
timer = setInterval('common()', 3000);
}

function init() {
let len = 5
for (let i = 0; i < len; i++) {
document.getElementById('slideshow-footbar').innerHTML +=
'<div class="slideshow-bt" index=' + (len - i) + '></div>'
}
let btns = document.getElementsByClassName('slideshow-bt');
btns[len - 1].className += ' bt-on';
for (let i = 0; i < btns.length; i++) {
btns[i].onclick = function() {
slideTo(this.getAttribute('index'))
}
}
timer = setInterval('common()', 3000);
}
        // 把定时器封装到函数中以免代码重复
function common() {
            // 判断是不是最后一张
if (currIndex + 1 > 5) {
currIndex = 1;
} else {
currIndex++;
}
slideTo(currIndex);
}

function slideTo(index) {
index = parseInt(index);
currIndex = index;
let picArr = document.getElementById('slideshow-photo').childNodes;
let btns = document.getElementsByClassName('slideshow-bt');
for (let i = 0; i < picArr.length; i++) {
if (picArr[i].nodeType === 1) {
if (parseInt(picArr[i].getAttribute('index')) === index) {
picArr[i].style.zIndex = 2;
} else {
picArr[i].style.zIndex = 1;
}
}
}
for (let i = 0; i < btns.length; i++) {
if (parseInt(btns[i].getAttribute('index')) === index) {
btns[i].className = 'slideshow-bt bt-on';
} else {
btns[i].className = 'slideshow-bt';
}
}
}
</script>
</body>

</html>

基于NSGA-III算法求解微电网多目标优化调度研究(Matlab代码实现)内容概要:本文围绕基于NSGA-III算法的微电网多目标优化调度展开研究,重点介绍了如何利用该先进多目标进化算法解决微电网系统中多个相互冲突的目标(如运行成本最小化、碳排放最低、供电可靠性最高等)的协同优化问题。文中结合Matlab代码实现,详细阐述了NSGA-III算法的基本原理、在微电网调度模型中的建模过程、约束条件处理、目标函数设计以及仿真结果分析,展示了其相较于传统优化方法在求解高维、非线性、多目标问题上的优越性。同时,文档还提供了丰富的相关研究案例和技术支持背景,涵盖电力系统优化、智能算法应用及Matlab仿真等多个方面。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事能源优化领域的工程技术人员;尤其适合正在进行微电网调度、多目标优化算法研究或撰写相关论文的研究者。; 使用场景及目标:①掌握NSGA-III算法的核心思想及其在复杂能源系统优化中的应用方式;②学习如何构建微电网多目标调度模型并利用Matlab进行仿真求解;③为科研项目、毕业论文或实际工程提供算法实现参考和技术支撑。; 阅读建议:建议读者结合文中提供的Matlab代码实例,逐步调试运行并深入理解算法流程与模型构建细节,同时可参考文档中列出的其他优化案例进行横向对比学习,以提升综合应用能力。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值