jq实现图片轮播:圆形焦点+左右控制+自动轮播
2014-10-02 00:26
597 查看
来源:http://www.ido321.com/862.html
html代码:
</script>
[/code]
css代码
[/code]
js代码:
[/code]
打包下载:http://download.csdn.net/detail/u011043843/7994017
html代码:
[code] <!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>JQ图片轮播</title>
<!-- css -->
<link rel="stylesheet" type="text/css" href="style.css">
<!-- js -->
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="style.js">
</script>
</head>
<body>
<div id="ad">
<ul>
<li>
<a href="#" title="位置1"><img src="ad.png"></a>
</li>
<li>
<a href="#" title="位置2"><img src="1.jpg"></a>
</li>
<li>
<a href="#" title="位置3"><img src="2.jpg"></a>
</li>
<li>
<a href="#" title="位置4"><img src="3.jpg"></a>
</li>
</ul>
</div>
<div class="slideshortcut">
<a id="SlidePrev" class="prev"><</a>
<a id="SlideNext" class="next">></a>
</div>
<div class="jiaodiandiv">
<ul>
<li id="selectli"><span>1</span></li>
<li><span>2</span></li>
<li><span>3</span></li>
<li><span>4</span></li>
</ul>
</div>
</body>
</html>
[/code]
css代码
[code] #ad
{
width: 1350px;
height: 370px;
overflow: hidden;
margin-left:-5px;
position: relative;
}
#ad ul
{
list-style: none;
position: absolute;
margin-left: -40px;
}
#ad ul li
{
float: left;
width: 1350px;
height: 370px;
position: relative;
}
.slideshortcut a
{
color: #000000;
text-decoration: none;
background-color: #fff;
display: block;
position: absolute;
z-index: 500;
top: 150px;
width: 50px;
height: 50px;
border: 1px solid red;
font-size: 40px;
line-height: 40px;
text-align: center;
opacity: 0;
}
.slideshortcut a:hover
{
color: #000000;
text-decoration: none;
}
.prev
{
left: 150px;
}
.next
{
left: 1200px;
}
.jiaodiandiv
{
position: absolute;
z-index: 200;
top: 320px;
left: 42%
}
.jiaodiandiv ul
{
list-style: none;
}
.jiaodiandiv ul li
{
width: 30px;
height: 30px;
margin-left: 10px;
float: left;
border: 1px solid #B7B7B7;
background-color: #B7B7B7;
border-radius:15px;
text-align: center;
}
#selectli
{
background-color: #FF4400;
}
.jiaodiandiv li:hover
{
cursor: pointer;
}
.jiaodiandiv span
{
font-size: 20px;
line-height: 30px;
}
[/code]
js代码:
[code] $(document).ready(function()
{
/*轮播*/
var index = 0;
var jdlis = $('.jiaodiandiv li'); /*焦点li元素集合*/
var timer;
var liWidth = $('#ad').width();
var len = $("#ad ul li").length;
//左右滚动,即所有li元素都是在同一排向左浮动,所以这里需要计算出外围ul元素的宽度
$("#ad ul").css("width",liWidth * (len));
//上一张按钮
$("#SlidePrev").click(function(){
clearInterval(timer);
index -= 1;
if(index == -1){index = len - 1;}
showPic(index);
});
//下一张按钮
$("#SlideNext").click(function(){
clearInterval(timer);
index += 1;
if(index == len){index = 0;}
showPic(index);
});
//轮播
$('#ad').hover(
function()
{
clearInterval(timer); /*停止动画*/
$('.slideshortcut a').show().css('opacity','0.4');
},
function()
{
$('.slideshortcut a').hide();
timer=setInterval(function(){
showPic(index);
index++;
if(index == len){index = 0;}
},2000);
}).trigger("mouseleave");
/*显示index图片*/
function showPic(index){
var nowLeft = -index*liWidth;
jdlis.eq(index).css('backgroundColor','#FF4400');
jdlis.not(jdlis.eq(index)).css('backgroundColor','#B7B7B7');
$("#ad ul").stop(true,false).animate({"left":nowLeft},300);
/*$('#loginimg').hide().fadeIn(1000);*/
}
$('.slideshortcut a').mouseover(function()
{
$('.slideshortcut a').show();
});
$('.prev').mouseover(
function()
{
$(this).css({opacity:'0.95',cursor:'pointer'});
});
$('.next').mouseover(
function()
{
$(this).css({opacity:'0.95',cursor:'pointer'});
});
/*点击焦点区的div显示对应图*/
jdlis.click(
function(){
clearInterval(timer);
index = jdlis.index(this);
showPic(index);
});
});
[/code]
打包下载:http://download.csdn.net/detail/u011043843/7994017
相关文章推荐
- jq实现图片轮播:圆形焦点+左右控制+自动轮播
- jquery图片轮播,点击左右按钮轮播,可控制是否自动播放,是否循环轮播(自写)
- Android实现图片自动轮播并且支持手势左右无限滑动
- jquery实现带左右箭头和数字焦点的图片轮播手写代码
- Android使用ViewPager实现图片轮播(高度自适应,左右循环,自动轮播)
- 【实践】纯jquery实现图片滑动无缝轮播,带左右按钮及控制按钮
- 最简单jquery实现带左右箭头和数字焦点的图片轮播
- Android实现图片自动轮播并且支持手势左右无限滑动
- jquery实现带左右箭头和数字焦点的图片轮播手写代码 (转)
- JavaScript实现简单的图片轮播(通过点击左右焦点切换)
- 教你用js超简单实现页面自动控制图片的宽度和高度
- js设置图片或文字自动左右滚动控制,鼠标经过停留
- Jquery实现图片左右滚动(自动)
- jquery图片滚动仿QQ商城带左右按钮控制焦点图片切换滚动
- 如何实现上下左右键盘控制焦点使之落在相邻文本框或下拉框中-Web开发/JavaScript
- javascript实现图片左右轮换效果(鼠标控制亦可)
- jquery实现jQuery实现图片轮播效果,jQuery实现焦点新闻
- jquery仿QQ商城带左右按钮控制焦点图片切换滚动效果
- css3 来实现图片在指定容器内等比例缩放,并控制中上下左右居中
- css实现div中的图片自动上下左右居中