点击轮换
2016-04-06 17:39
99 查看
script:
$(function () {
var sWidth = $("#smfocus").width();
var len = $("#smfocus 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>";
$("#smfocus").append(btn);
$("#smfocus .btnBg").css("opacity", 0);
$("#smfocus .btn span").css("opacity", 0.4).mouseenter(function () {
index = $("#smfocus .btn span").index(this);
showPics(index);
}).eq(0).trigger("mouseenter");
$("#smfocus .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);
});
$("#smfocus .pre").click(function () {
index -= 1;
if (index == -1) { index = len - 1; }
showPics(index);
});
$("#smfocus .next").click(function () {
index += 1;
if (index == len) { index = 0; }
showPics(index);
});
$("#smfocus ul").css("width", sWidth * (len));
$("#smfocus").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;
$("#smfocus ul").stop(true, false).animate({ "left": nowLeft }, 300);
$("#smfocus .btn span").stop(true, false).animate({ "opacity": "0.4" }, 300).eq(index).stop(true, false).animate({ "opacity": "1" }, 300);
}
});
css:
#smfocus {overflow: hidden; position: relative;}
#smfocus ul {width: 200px; height: 250px; float: left; position: absolute; clear: both; padding: 0px; margin: 0px; }
#smfocus ul li { float: left;}
#smfocus .preNext {width: 200px; height: 250px; position: absolute; top: 0px; cursor: pointer; }
#smfocus .pre {width: 22px; left: 0;background: url(../images/ljiantou.jpg) no-repeat left center; display: block;}
#smfocus .next {width: 38px; right: 0; background: url(../images/rjiantou.jpg) no-repeat right center; display: block;}
html:
<div class="examplef" id="smfocus">
<ul>
<li>
<a href="#" target="_blank">
<img src="images/zs.jpg" alt="" /></a>
</li>
<li>
<a href="#" target="_blank">
<img src="images/zs.jpg" alt="" /></a>
</li>
<li>
<a href="#" target="_blank">
<img src="images/zs.jpg" alt="" /></a>
</li>
<li>
<a href="#" target="_blank">
<img src="images/zs.jpg" alt="" /></a>
</li>
</ul>
</div>
$(function () {
var sWidth = $("#smfocus").width();
var len = $("#smfocus 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>";
$("#smfocus").append(btn);
$("#smfocus .btnBg").css("opacity", 0);
$("#smfocus .btn span").css("opacity", 0.4).mouseenter(function () {
index = $("#smfocus .btn span").index(this);
showPics(index);
}).eq(0).trigger("mouseenter");
$("#smfocus .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);
});
$("#smfocus .pre").click(function () {
index -= 1;
if (index == -1) { index = len - 1; }
showPics(index);
});
$("#smfocus .next").click(function () {
index += 1;
if (index == len) { index = 0; }
showPics(index);
});
$("#smfocus ul").css("width", sWidth * (len));
$("#smfocus").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;
$("#smfocus ul").stop(true, false).animate({ "left": nowLeft }, 300);
$("#smfocus .btn span").stop(true, false).animate({ "opacity": "0.4" }, 300).eq(index).stop(true, false).animate({ "opacity": "1" }, 300);
}
});
css:
#smfocus {overflow: hidden; position: relative;}
#smfocus ul {width: 200px; height: 250px; float: left; position: absolute; clear: both; padding: 0px; margin: 0px; }
#smfocus ul li { float: left;}
#smfocus .preNext {width: 200px; height: 250px; position: absolute; top: 0px; cursor: pointer; }
#smfocus .pre {width: 22px; left: 0;background: url(../images/ljiantou.jpg) no-repeat left center; display: block;}
#smfocus .next {width: 38px; right: 0; background: url(../images/rjiantou.jpg) no-repeat right center; display: block;}
html:
<div class="examplef" id="smfocus">
<ul>
<li>
<a href="#" target="_blank">
<img src="images/zs.jpg" alt="" /></a>
</li>
<li>
<a href="#" target="_blank">
<img src="images/zs.jpg" alt="" /></a>
</li>
<li>
<a href="#" target="_blank">
<img src="images/zs.jpg" alt="" /></a>
</li>
<li>
<a href="#" target="_blank">
<img src="images/zs.jpg" alt="" /></a>
</li>
</ul>
</div>
相关文章推荐
- 那些年奇葩的面试题
- margin与padding
- android5.0与android4.3中的栈的源码分析比较
- get/post请求中文乱码问题
- RAII和模拟实现智能指针
- A Byte of Python 笔记(10)输入/输出:文件和储存器
- 价值观
- PhotoKit 详解
- free(p)后指针问题
- 啊哈算法学习-快速排序
- HttpRequestMethodNotSupportedException
- 四则运算 结对编程
- 帧动画FrameAnimation
- ASP.NET MVC路由配置详解
- 【iOS和HTML 5交互】iOS中加载html5调用html方法和修改html5内容
- 图片
- P2P理财投资过程中要注意哪些点
- VS2013仿真emwin[ucgui]时出现编译错误的解决方法
- .NET下实现分布式缓存系统Memcached
- hdu4289(拆点最大流)