//首页无缝轮播
;
(function($, window, document, undefined) { $.fn.slider = function(options) { var defaults = { //默认参数
delay: 3000, //间隔
speed: 600, //速度
auto: false, //自动否
shiying: false //适应否 }; var settings = $.extend({}, defaults, options); //合并参数 {}防覆盖 var _this = this;
var li = _this.find('li');
var w = li.eq(0).width();
var len = li.length - 1;
var index = 0;
var autoPlay; function init() {
if(settings.shiying) { shiying(); }; left();
right();
if(settings.auto) { auto(); }; } init(); function shiying() { var wid = $(document.body).outerWidth(true) + 17;
li.width(wid);
alert(wid);
$(window).resize(function() {
wid = $(document.body).outerWidth(true) + 17;
li.width(wid); }) var data_src = [];
for(var i = 0; i < li.length; i++) { data_src.push(li.eq(i).find("img").attr("src")); li.eq(i).css({
'background': 'url(' + data_src[i] + ') no-repeat center center'
}); } li.find('img').remove(); }; function left() { _this.find('.arrow_left').on('click', function() { if(_this.find('ul').is(":animated")) {
return;
}; play(); }); }; function right() { _this.find('.arrow_right').on('click', function() {
if(_this.find('ul').is(":animated")) {
return;
}; if(index < 1) { _this.find('ul').append(li.eq(len).clone()); _this.find('ul').css({
'marginLeft': -w * (len + 1)
}); //此处clone了一个新的 所以需要加一 index = len;
_this.find('.dots span').eq(index).addClass('active').siblings().removeClass('active'); _this.find('ul').stop().animate({
'marginLeft': -w * index
}, function() { _this.find('li:last').remove(); }); } else { index--; _this.find('ul').stop().animate({
'marginLeft': -w * index
}); _this.find('.dots span').eq(index).addClass('active').siblings().removeClass('active'); } }); }; function play() { if(index > len - 1) {
index++; _this.find('ul').prepend(li.eq(0).clone()); _this.find('ul').stop().animate({
'marginLeft': -w * index
}, function() {
_this.find('ul').css({
'marginLeft': 0
});
_this.find('li:first').remove();
index = 0;
_this.find('.dots span').eq(index).addClass('active').siblings().removeClass('active'); }); } else {
index++;
_this.find('.dots span').eq(index).addClass('active').siblings().removeClass('active'); _this.find('ul').stop().animate({
'marginLeft': -w * index
}); } }; function auto() { autoPlay = setInterval(play, settings.delay); }; function dots() { var $dots = $('<div class="dots"></div>'); for(var i = 0; i < li.length; i++) { var dot_span = $('<span></span>'); $dots.append(dot_span);
} _this.append($dots);
$('.dots span:first').addClass('active'); _this.find('.dots span').on('click', function() { $(this).addClass('active').siblings().removeClass('active');
var index_dot = $(this).index(); //alert(index_dot);
index = index_dot; _this.find('ul').stop().animate({
'marginLeft': -w * index
}); }); } dots(); _this.hover(function() { clearInterval(autoPlay); }, function() { autoPlay = setInterval(play, settings.delay); } ) }; })(jQuery, window, document);

借着上次的小项目,自己做了一个小的轮播插件,实现了,但是还有有许多的问题。

一时响应式时有问题,图片不能跟随,后续我会尝试用unslider里的imgReload方法进行改进,这里做一个标记.

imgReload

function imgReload()

{

    var imgHeight = 0;

    var wtmp = $("body").width();

    $("#banner ul li").each(function(){

        $(this).css({width:wtmp + "px"});

    });

    $(".sliderimg").each(function(){

        $(this).css({width:wtmp + "px"});

        imgHeight = $(this).height();

    });

}

$(window).resize(function(){imgReload();});

然后是init方法,自己完全是瞎搞。

后续会尝试用面向对象的方法去改造。

jquery做一个小的轮播插件---有BUG,后续修改的更多相关文章

  1. 使用jQuery做简单的图片轮播效果

      一.本特效主要用到的前端知识点 CSS中绝对定位(absolute)CSS实现垂直居中jQuery中简单的淡入淡出动画效果(fadeIn,fadeOut)定时器(setInterval,clear ...

  2. 实现一个3D图片轮播插件 —— 更新版

    前言:     前段时间写下了之前那篇 3D图片轮播效果,后来发现了 Pedro Botelho 写的jquery.gallery.js ,于是重新修改了自己的这个图片轮播,使之可以成为一个插件来使用 ...

  3. jquery制作一个简单的轮播

    效果图: 演示地址: http://ae6623.cn/demo/slider/index.html 思路: 利用css的定位属性 left 进行调整图片的显示,每次点击上一页下一页按钮的时候,-图片 ...

  4. (转)jQuery轻量级响应式图片轮播插件ResponsiveSlides.js(仅1kb)也可以做纯文本轮播

    ResponsiveSlides.js是一个展示同一容器内图片的轻量级响应式jQuery幻灯片插件(tiny responsive slideshow jQuery plugin).它支持包括IE6在 ...

  5. 图片轮播插件-carouFredSel

    carouFredSel图片轮播插件基于Jquery,比较常规的轮播插件,支持滚轮及键盘左右按键,加入其它插件可实现更加复杂的特效. 主页地址:http://caroufredsel.dev7stud ...

  6. 关于最近在做的一个js全屏轮播插件

    最近去面试了,对方要求我在一个星期内用原生的js代码写一个全屏轮播的插件,第一想法就是跟照片轮播很相似,只是照片轮播是有定义一个宽高度大小已经确定了的容器用来存储所有照片,然后将照片全部左浮动,利用m ...

  7. 自己写的一个jQuery轮播插件

    大概是四月初开始写的,中间停了有一个月吧.这是我在Github的第一个项目.项目地址:https://github.com/linzb93/jquery.slide.js. 轮播应该是最好写的插件了, ...

  8. Javascript和jQuery WordPress 图片轮播插件, 内容滚动插件,前后切换幻灯片形式显示

    用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美的图片轮播效果,希望这些插件 ...

  9. PgwSlideshow-基于Jquery的图片轮播插件

    0 PgwSlideshow简介 PgwSlideshow是一款基于Jquery的图片轮播插件,基本布局分为上下结构,上方为大图轮播区域,用户可自定义图片轮播切换的间隔时间,也可以通过单击左右方向按键 ...

随机推荐

  1. Python抽象类(abc模块)

    1.抽象类概念 抽象类是一个特殊的类,只能被继承,不能实例化 2.为什么要有抽象类 其实在未接触抽象类概念时,我们可以构造香蕉.苹果.梨之类的类,然后让它们继承水果这个基类,水果的基类包含一个eat函 ...

  2. iview2.0 日期选择器DatePicker 所选时间格式不对

    网上有很多解决方式,大部分都是加个@on-change事件.比如下图: 但是如果是编辑的时候,打开编辑页面,通过数据库返回时间显示出来是对的,但是不触发change事件,直接点保存的话,保存后还是少8 ...

  3. 2019hdu多校 Minimal Power of Prime

    题目链接:Click here 题目大意:求一个数分解质因数后的最小幂指数 Solution: 首先,我们肯定是不能直接暴力求解的 我们先考虑筛出1e4范围以内的所有质数,把x所有这个范围内的质因子筛 ...

  4. Anaconda是如何进行版本管理的?

    创建不同的environments,在电脑中会有不同的文件夹 然后,当使用conda下载时,会下载到不同的env文件夹下(提前进行env切换) 那么不是在anaconda prompt命令行下下载的呢 ...

  5. wordcloud:让你的词语像云朵一样美

    介绍   对文本中出现频率较高的关键词给予视觉化的显示 使用 python import jieba import codecs import wordcloud file = r"C:\U ...

  6. python3.x使用cxfreeze将.p打包成.exe

    之前写了一个使用ffplay批量查看格式为h264的图片,每次抽帧后都要打开pycharm编译器来运行程序,然后才能正常查看图片,或者在其他没有安装python环境的电脑中运行,很不方便.为此,在网上 ...

  7. 第五周总结 & 实验报告(三)

    第五周总结 一.继承       1.类的继承格式 class 父类{} class 子类 extends 父类{} 2.扩展类的功能 class 父类{ 父类属性: .......... ..... ...

  8. code first System.Data.Entity.Infrastructure.CommitFailedException: An error was reported while committing a database transaction but it could not be determined whether the transaction succeeded

    System.Data.Entity.Infrastructure.CommitFailedException: An error was reported while committing a da ...

  9. Python中的self用法之面向对象

    class Student(object): def __init__(self, name, score): self.__name = name self.__score = score def ...

  10. 后台以json数据形式返回之后前台接受的方法以及之后的解析总结

    1.前台AJAX请求,后台以对象转JSON形式返回: 后台代码: @RequestMapping(value = "/queryDist", method = RequestMet ...