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. 横竖屏切换Activity的生命周期

    横竖屏切换的时候Activity的生命周期如下: 1.新建一个Activity,并把各个生命周期打印出来 2.运行Activity,得到如下信息 onCreate--> onStart--> ...

  2. Manjro i3 桌面 添加输入法 及无声音配置方法(This sound device does not have any capture controls.问题)

    一.i3桌面添加输入法 1.把配置写在 /etc/environment中 export GTK_IM_MODULE=fcitx export QT_IM_MODULE=fcitx export XM ...

  3. P3381 【模板】最小费用最大流(spfa板子)

    #include<bits/stdc++.h> using namespace std; #define lowbit(x) ((x)&(-x)) typedef long lon ...

  4. 【高软作业4】:Tomcat 观察者模式解析 之 Lifecycle

    一. 预备 如果你是Windows用户,使用Eclipse,并且想自行导入源码进行分析,你可能需要:Eclipse 导入 Tomcat 源码 如果你已遗忘 观察者模式,那么你可以通过该文章回顾:设计模 ...

  5. 七 Hibernate5种查询检索方式,单表&多表

    Hibernate中提供了5种查询方式: OID查询 对象导航查询 HQL检索 QBC检索 SQL检索 OID检索: Hibernate根据对象的oid(表中主键) 使用get方法   Custome ...

  6. Tomcat启动时加载数据到缓存---web.xml中listener加载顺序(例如顺序:1、初始化spring容器,2、初始化线程池,3、加载业务代码,将数据库中数据加载到内存中)

    最近公司要做功能迁移,原来的后台使用的Netty,现在要迁移到在uap上,也就是说所有后台的代码不能通过netty写的加载顺序加载了. 问题就来了,怎样让迁移到tomcat的代码按照原来的加载顺序进行 ...

  7. HiBench成长笔记——(7) 阅读《The HiBench Benchmark Suite: Characterization of the MapReduce-Based Data Analysis》

    <The HiBench Benchmark Suite: Characterization of the MapReduce-Based Data Analysis>内容精选 We th ...

  8. 使用python将请求的requests headers参数格式化方法

    import json # 使用三引号将浏览器复制出来的requests headers参数赋值给一个变量 headers = """ Host: zhan.qq.com ...

  9. 我的C语言的新开端<graphics.h>

    进一步接触C语言<graphics.h> #include<stdio.h> #include<graphics.h> #include<conio.h> ...

  10. oracle,uuid为主键,插入时直接更新id

    uuid为主键,插入时自动更新 -- Create table create table TECHNOLOGYCOMPANY ( ID VARCHAR2(32) default SYS_GUID() ...