jQuery实现图片简单轮播功能示例
本文实例讲述了jQuery实现图片简单轮播功能。分享给大家供大家参考,具体如下:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>www.jb51.net jQuery图片轮播</title>
<style type="text/css">
#frame{
width:700px;
height:300px;
position:relative;
}
#img2,#img3{
display:none;
}
.box{
position:absolute;
width:50px;
height:50px;
line-height:50px;
text-align:center;
color:white;
font-family:Microsoft-Yahei;
background:grey;
}
#move1{
bottom:0;
right:100px;
}
#move2{
bottom:0;
right:50px;
}
#move3{
bottom:0;
right:0;
}
</style>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
n = 1;
interval = setInterval(
function(){
$("img").hide();
$("#img"+n).show();
$(".box").css("background","grey");
$("#move"+n).css("background","red");
n = n % 3 + 1;
}
,
2000
);
$(".box").bind("click",function() {
clearInterval(interval);
n = $(this).attr("id").slice(4);
interval = setInterval(
function(){
$("img").hide();
$("#img"+n).show();
$(".box").css("background","grey");
$("#move"+n).css("background","red");
n = n % 3 + 1;
}
,
2000
);
});
});
</script>
</head>
<body>
<div id="frame">
<div id="photos">
<img id="img1" src="images/background1.png">
<img id="img2" src="images/background2.png">
<img id="img3" src="images/background3.png">
</div>
<div class="box" id="move1">1</div>
<div class="box" id="move2">2</div>
<div class="box" id="move3">3</div>
</div>
</body>
</html>
感兴趣的朋友可以使用在线HTML/CSS/JavaScript代码运行工具:http://tools.jb51.net/code/HtmlJsRun 测试运行效果(记得替换上述图片为网络图片)
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery图片操作技巧大全》、《jQuery表格(table)操作技巧汇总》、《jQuery切换特效与技巧总结》、《jQuery扩展技巧总结》、《jQuery常用插件及用法总结》、《jQuery常见经典特效汇总》及《jquery选择器用法总结》
希望本文所述对大家jQuery程序设计有所帮助。
相关文章
jQuery中bind(),live(),delegate(),on()绑定事件方法实例详解
这篇文章主要介绍了jQuery中bind(),live(),delegate(),on()绑定事件方法,结合实例形式详细分析了bind(),live(),delegate(),on()方法绑定事件的具体使用技巧,并对比分析了四种方式的异同点,需要的朋友可以参考下2016-01-01
JQuery的Ajax中Post方法传递中文出现乱码的解决方法
这篇文章主要介绍了JQuery的Ajax中Post方法传递中文出现乱码的解决方法,较为深入的分析了Ajax的post方法出现乱码的原因,以及具体的解决方法,需要的朋友可以参考下2014-10-10
逐一介绍Jquery data()、Jquery stop()、jquery delay()函数(详)
这篇文章逐一介绍Jquery data()、Jquery stop()、jquery delay()函数(详)的相关资料,需要的朋友可以参考下2015-11-11
基于jquery中children()与find()的区别介绍
本篇文章介绍了,基于jquery中children()与find()的区别,需要的朋友参考下2013-04-04


最新评论