- ; (function ($) {
- $.extend({
- 'foucs': function (con) {
- var $container = $('#index_b_hero')
- , $imgs = $container.find('li.hero')
- , $leftBtn = $container.find('a.prev')
- , $rightBtn = $container.find('a.next')
- , config = {
- interval: con && con.interval || 3500,
- animateTime: con && con.animateTime || 500,
- direction: con && (con.direction === 'right'),
- _imgLen: $imgs.length
- }
- , i = 0
- , getNextIndex = function (y) { return i + y >= config._imgLen ? i + y - config._imgLen : i + y; }
- , getPrevIndex = function (y) { return i - y < 0 ? config._imgLen + i - y : i - y; }
- , silde = function (d) {
- $imgs.eq((d ? getPrevIndex(2) : getNextIndex(2))).CSS('left', (d ? '-1920px' : '1920px'))
- $imgs.animate({
- 'left': (d ? '+' : '-') + '=960px'
- }, config.animateTime);
- i = d ? getPrevIndex(1) : getNextIndex(1);
- }
- , s = setInterval(function () { silde(config.direction); }, config.interval);
- $imgs.eq(i).css('left', 0).end().eq(i + 1).css('left', '960px').end().eq(i - 1).css('left', '-960px');
- $container.find('.hero-wrap').add($leftBtn).add($rightBtn).hover(function () { clearInterval(s); }, function () { s = setInterval(function () { silde(config.direction); }, config.interval); });
- $leftBtn.click(function () {
- if ($(':animated').length === 0) {
- silde(false);
- }
- });
- $rightBtn.click(function () {
- if ($(':animated').length === 0) {
- silde(true);
- }
- });
- }
- });
- }(jQuery));
- //该片段来自于http://www.codesnippet.cn/detail/040320148867.html
来源: http://www.codesnippet.cn/detail/040320148867.html