1,slider.js

/**
* slider插件可悬停控制
*/
; $(function ($, window, document, undefined) {
 
Slider = function (container, options) {
/*
options = {
auto: true,
time: 3000,
event: 'hover' | 'click',
mode: 'slide | fade',
controller: $(),
activeControllerCls: 'className',
exchangeEnd: $.noop
}
*/
"use strict"; //strict mode not support by IE9-
if (!container) return;
var options = options || {},
currentIndex = 0,
cls = options.activeControllerCls,
delay = options.delay,
isAuto = options.auto,
controller = options.controller,
event = options.event,
interval,
slidesWrapper = container.children().first(),
slides = slidesWrapper.children(),
length = slides.length,
childWidth = container.width(),
totalWidth = childWidth * slides.length;
function init() {
var controlItem = controller.children();
mode();
event == 'hover' ? controlItem.mouseover(function () {
stop();
var index = $(this).index();
play(index, options.mode);
}).mouseout(function () {
isAuto && autoPlay();
}) : controlItem.click(function () {
stop();
var index = $(this).index();
play(index, options.mode);
isAuto && autoPlay();
});
isAuto && autoPlay();
}
//animate mode
function mode() {
var wrapper = container.children().first();
options.mode == 'slide' ? wrapper.width(totalWidth) : wrapper.children().css({
'position': 'absolute',
'left': 0,
'top': 0
})
.first().siblings().hide();
}
//auto play
function autoPlay() {
interval = setInterval(function () {
triggerPlay(currentIndex);
}, options.time);
}
//trigger play
function triggerPlay(cIndex) {
var index;
(cIndex == length - 1) ? index = 0 : index = cIndex + 1;
play(index, options.mode);
}
//play
function play(index, mode) {
slidesWrapper.stop(true, true);
slides.stop(true, true);
mode == 'slide' ? (function () {
if (index > currentIndex) {
slidesWrapper.animate({
left: '-=' + Math.abs(index - currentIndex) * childWidth + 'px'
}, delay);
} else if (index < currentIndex) {
slidesWrapper.animate({
left: '+=' + Math.abs(index - currentIndex) * childWidth + 'px'
}, delay);
} else {
return;
}
})() : (function () {
if (slidesWrapper.children(':visible').index() == index) return;
slidesWrapper.children().fadeOut(delay).eq(index).fadeIn(delay);
})();
try {
controller.children('.' + cls).removeClass(cls);
controller.children().eq(index).addClass(cls);
} catch (e) { }
currentIndex = index;
options.exchangeEnd && typeof options.exchangeEnd == 'function' && options.exchangeEnd.call(this, currentIndex);
}
//stop
function stop() {
clearInterval(interval);
}
//prev frame
function prev() {
stop();
currentIndex == 0 ? triggerPlay(length - 2) : triggerPlay(currentIndex - 2);
isAuto && autoPlay();
}
//next frame
function next() {
stop();
currentIndex == length - 1 ? triggerPlay(-1) : triggerPlay(currentIndex);
isAuto && autoPlay();
}
function a(){
alert('aaa')
}
//init
init();
//expose the Slider API
return {
prev: function () {
prev();
},
next: function () {
next();
},
stop: function(){
stop()
}

autoPlay:function(){
autoPlay()
}
}
};
}(jQuery, window, document));
 
2,主页调用,提前调用jquery,再调用slider.js
<script type="text/javascript">
$(function () {
 
var bannerSlider = new Slider($('#banner_tabs'), {
time: 2000,
delay: 400,
event: 'hover',
auto: true,
mode: 'fade',
controller: $('#bannerCtrl'),
activeControllerCls: 'active'
});
 
$('#banner_tabs .flex-prev').click(function () {
bannerSlider.prev()
});
$('#banner_tabs .flex-next').click(function () {
bannerSlider.next()
});
$('.悬停的区域').mouseenter(function () {
bannerSlider.stop()
})

$('.悬停离开后').mouseleave(function () {
bannerSlider.autoPlay()
})
})
</script>

jquery - 导航轮播图的更多相关文章

  1. 用jQuery实现轮播图效果,js中的排他思想

    ---恢复内容开始--- jQuery实现轮播图不用单独加载. 思路: a. 通过$("#id名");选择需要的一类标签,获得一个伪数组 b.由于是伪数组的原因,而对数组的处理最多 ...

  2. 用js和jQuery做轮播图

    Javascript或jQuery做轮播图 css样式 <style> a{ text-decoration:none; } .naver{ width: 100%; position:r ...

  3. 自实现PC端jQuery版轮播图

    最近其他项目不是很忙,被安排给公司的官网项目做一个新的页面(之前没接触公司官网项目),其中有一个用到轮播图的地方,最开始想直接用swiper.js插件实现就好了,可是发现官网项目里之前都没有引入过sw ...

  4. JQuery实现轮播图及其原理

    源码: <!DOCTYPE html> <html> <head> <meta charset="utf-8" name="vi ...

  5. Jquery无缝轮播图的制作

    轮播是html页面中比较常见的一种展现形式,也是基础,把轮播图做好,是排版中比较关键的 1.首先是轮播的html元素放置:做轮播之前,要有一个初步的认识 2.每个元素的位置怎样摆放,也是很关键的,这里 ...

  6. jquery优化轮播图2

    继续优化 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  7. jquery改造轮播图1

    g改造轮播图1:https://www.cnblogs.com/huanghuali/p/8677338.html <!DOCTYPE html> <html lang=" ...

  8. jQuery无缝轮播图思路详解-唯品会

    效果图如上: 需求:图片自动轮播,鼠标移上停止播放,离开恢复播放,箭头切换图片. html代码 <!--轮播图大盒子开始--> <div class="wrap" ...

  9. jQuery封装轮播图插件

    // 布局要求,必须有一个容器,图片和两个按钮,布局方式自定,小圆点样式固定 // <div class="all"> // <img src="img ...

随机推荐

  1. 剑指offer 把数组排成最小的数 atoi和itoa,pow

    pow(x,y)在#include<math.h>文件中,计算x的y次方. C++引入头文件:#include <stdlib.h> 或者 #include <cstdl ...

  2. 关于MySQL连接Navicat Premium 12失败的解决方法

    出现问题的原因:MySQL8.0之后更换了加密方式,而这种加密方式客户端不支持 解决:更改加密方式 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysq ...

  3. php 实现店铺装修1

    一.原型分析 1.店铺未装修的情况下,使用默认样式,哪个是默认样式由后台告知: 2.所有的样式由后台进行维护(但后台始终有一个默认样式,不可删除不可编辑),所有样式,只要用户未编辑过,则默认按照商品的 ...

  4. python 函数map()、filter()、reduce()

    map()函数    将一个列表进行遍历,对每一个字符串进行处理: 例如: num_list = ["我","是","哈哈","太 ...

  5. Lesson 4 Seeing hands

    How did vera discover she had this gift of second sight? Several cases have been reported in Russia ...

  6. zabbix WebUI自定义Nginx监控项模板

    zabbix webUI自定义Nginx监控项模板 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.创建模板 1>.如下图所示,依次点击"配置" --- ...

  7. Windows驱动开发-r3和r0通信

    用户部分代码: int main() { HANDLE hDevice = CreateFile(L, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ...

  8. Mac 终端启动AVD模拟器

    cd ~/Library/Android/sdk/tools ./emulator -list-avds // 列出av列表 Nexus_5X_API_26 ./emulator @Nexus_5X_ ...

  9. RTL8711AM

    官方文档主要修改 为了实现log服务 1,在log_service.h 取消注释 #ifndef LOG_SERVICE_H #define LOG_SERVICE_H #include " ...

  10. f_lseek

    我在STM32中移植了fatfs文件系统,实现在SD卡对文件的读写.在普通读写中都没有问题,但是一旦我关闭文件系统,再次打开读写,之前写的数据就被覆盖.比如举个例子:       u8 tx_buff ...