//首页无缝轮播
;
(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. redis 日志等级说明

    redis loglevel 安装默认的设置为 verbose 1)debug:会打印出很多信息,适用于开发和测试阶段 2)verbose(冗长的):包含很多不太有用的信息,但比debug要清晰一些 ...

  2. DevExpress.XtraGrid.Views.Grid.GridView

    private void SetView() { GridView gridView = (GridView)this.DefaultView; if (gridView != null) { gri ...

  3. C# walls

    在学习C#的阶段中,我们一点一点的往前爬, 此代码需要添加selenium ,和 获取 引用. using Ivony.Html.Parser; using Ivony.Html; using Ope ...

  4. 20道JS原理题助你面试一臂之力!(转)

    20道JS原理题助你面试一臂之力! 前言 本文针对目前常见的面试题,仅提供了相应的核心原理及思路,部分边界细节未处理.后续会持续更新,希望对你有所帮助. 1. 实现一个call函数 // 思路:将要改 ...

  5. splice()、slice()、split()函数的区分

    1.slice(数组) 用法:array.slice(start,end) 解释:该方法是对数组进行部分截取,并返回一个数组副本:参数start是截取的开始数组索引,end参数等于你要取的最后一个字符 ...

  6. [LeetCode]-DataBase-Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  7. 使用HeapAnalyzer分析内存泄漏

    从IBM网站下载ha433包,释放,执行ha433.jar文件 https://www.ibm.com/developerworks/mydeveloperworks/groups/service/h ...

  8. centos设置定时删除文件定时清理网站日志

    1.进入linux系统 2.在任意目录创建一个sh后缀的文件,如: 3.编辑打开该文件,如图: 4.此时按键盘上的“i”键或者“insert”键,进入编辑模式 输入: #!/bin/shfind /d ...

  9. layer系列之table导出+打印功能总结

    1.关于layui导出方式,直接使用layui(版本2.4.5及以上)自带的导出方法即可: layui官网地址:https://www.layui.com/ 源码如下: <!DOCTYPE ht ...

  10. 数据结构和算法(Java版)快速学习(数组Array)

    Java数组 在Java中,数组是用来存放同一种数据类型的集合,注意只能存放同一种数据类型. 用类封装数组实现数据结构 数据结构必须具有以下基本功能: ①.如何插入一条新的数据项 ②.如何寻找某一特定 ...