首页 / JQUERY / jquery控制图片切换
jquery控制图片切换
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了jquery控制图片切换,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3056字,纯文字阅读大概需要5分钟。
内容图文
这种js现在用的很多。同时网上的js代码页很多。我直接从网上当了一个来用;代码如下:
html
<div
class="bannerbox">
<div
id="focus">
<ul>
<li><a href="#"
target="_blank">
<img src="../images/index_18.gif"
/></a></li>
<li><a href="#"
target="_blank">
<img src="../images/index_18.gif"
/></a></li>
<li><a href="#"
target="_blank">
<img src="../images/index_18.gif"
/></a></li>
<li><a href="#"
target="_blank">
<img src="../images/index_18.gif"
/></a></li>
</ul>
</div>
</div>
css:
.bannerbox { width: 970px; height: 447px; overflow: hidden; margin: 0px auto;
}
#focus { border:none;width: 970px; height: 447px; clear: both; overflow:
hidden; position: relative; float: left;z-index: 10 }
#focus ul { width:
970px; height: 447px; float: left; position: absolute; clear: both; padding:
0px; margin: 0px; border: none}
#focus ul li { float: left; width: 970px;
height: 447px; overflow: hidden; position: relative; padding: 0px;
margin:0;border: none }
#focus .preNext { width: 550px; height: 440px;
position: absolute; top: 2px; cursor: pointer;border: none;}
#focus .pre {
left: 0; background: url(../images/sprite.png) no-repeat left center;z-index:
20;border: none; }
#focus .next { right: 0; background:
url(../images/sprite1.png) no-repeat right center;z-index: 20;border: none;
}
jquery:
$(function () {
var sWidth =
$("#focus").width();
var len = $("#focus ul
li").length;
var index = 0;
var
picTimer;
var btn = "<div
class=‘btnBg‘></div><div class=‘btn‘>";
for
(var i = 0; i < len; i++) {
btn
+= "<span></span>";
}
btn += "</div><div class=‘preNext pre‘></div><div
class=‘preNext next‘></div>";
$("#focus").append(btn);
$("#focus .btnBg").css("opacity",
0);
$("#focus .btn span").css("opacity",
0.4).mouseenter(function () {
index = $("#focus .btn
span").index(this);
showPics(index);
}).eq(0).trigger("mouseenter");
$("#focus
.preNext").css("opacity", 0.0).hover(function ()
{
$(this).stop(true,
false).animate({ "opacity": "0.5" }, 300);
}, function ()
{
$(this).stop(true,
false).animate({ "opacity": "0" }, 300);
});
$("#focus .pre").click(function ()
{
index -=
1;
if (index == -1) { index = len
- 1; }
showPics(index);
});
$("#focus
.next").click(function () {
index
+= 1;
if (index == len) { index =
0; }
showPics(index);
});
$("#focus
ul").css("width", sWidth * (len));
$("#focus").hover(function () {
clearInterval(picTimer);
}, function ()
{
picTimer = setInterval(function
() {
showPics(index);
index++;
if (index == len) { index = 0; }
}, 2800);
}).trigger("mouseleave");
function showPics(index) {
var
nowLeft = -index * sWidth;
$("#focus ul").stop(true, false).animate({ "left": nowLeft },
300);
$("#focus .btn
span").stop(true, false).animate({ "opacity": "0.4" }, 300).eq(index).stop(true,
false).animate({ "opacity": "1" }, 300);
}
});
以上代码经测试在ie9以上,ff,chroom下运行正常。代码参考懒人图库
原文:http://www.cnblogs.com/lightinblack/p/3643843.html
内容总结
以上是互联网集市为您收集整理的jquery控制图片切换全部内容,希望文章能够帮你解决jquery控制图片切换所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。