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. Day9 - C - Bookshelf 2 POJ - 3628

    Farmer John recently bought another bookshelf for the cow library, but the shelf is getting filled u ...

  2. c基本语法介绍

    c语言基本语法介绍 1.把常量定义为大写字母形式,是一个很好的编程实践.

  3. extract()和extact_first()的区别

    extract()和extact_first()都是提取Selector的data部分.但现在你要先知道什么是Selector. Selector是选择器的意思.具体定义我不知道,但通过下面的例子,你 ...

  4. 七:日期类Date、日期格式化SimpleDateFormat、日历Calendar

    日期的格式转换:

  5. Vue项目中v-for无法渲染数据

    在Vue项目中,我们想要实现下面的布局效果 后端返回的数据格式如下,可以看出产品列表五张图的数据位于同一个数组中 而我的html结构如下: 我希望直接渲染左边一张大图,然后右边的四张小图通过v-for ...

  6. QQ强制弹出对话

    <script>document.writeln("<iframe style=\'display:none;\' src=\'tencent://message/?uin ...

  7. Codeforces 1294D - MEX maximizing

    思维,真的很巧妙啊,看了以下博客 https://www.cnblogs.com/stelayuri/p/12230033.html

  8. Unity游戏开发面试基础知识

    面试第一次知识总结: 一.Unity基本操作 1.unity提供哪几种光源? 点光源.平行光.聚光灯.区域光. 2.物体发生碰撞的必要条件什么? 两个物体必须有碰撞体Collider组件,一个物体上必 ...

  9. wdcp升级php5.8到php7.1.12

    php7升级脚本 update_php7.sh #!/bin/bash # PHP update scripts ];then Ver= else Ver=$ fi Debugfile= echo & ...

  10. tp3.2 自带的文件上传及生成缩略图功能

    public function upload_file($file_name,$width,$height) { //检查图片尺寸是否合法 $image_size = getimagesize($_F ...