//首页无缝轮播
;
(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. Luogu P3408 恋爱

    题目链接:Click here Solution: 设f[x]表示要使x向它的父亲写信需要花的最少的钱,per[x]为要使x向它的父亲写信最少要多少人 则\(f[x]=\sum_{i=1}^{per[ ...

  2. 算法设计与分析 1.2 不一样的fibonacci数列 (矩阵快速幂思想)

    题目描述 Winder 最近在学习 fibonacci 数列的相关知识.我们都知道 fibonacci 数列的递推公式是F(n) = F(n - 1) + F(n - 2)(n >= 2 且 n ...

  3. Java课堂动手动脑

    1.使用Files. walkFileTree()找出指定文件夹下所有大于指定大小(比如1M)的文件: 代码: package test; import java.io.IOException; im ...

  4. Python文件对象方法

    使用open()函数创建一个文件对象,这里是可以在这个对象上调用的函数的列表 - 编号 方法名称 描述 1 file.close() 关闭文件,无法读取或写入关闭的文件. 2 file.flush() ...

  5. Spring Boot教程(十八)构建RESTful API

    首先,回顾并详细说明一下在快速入门中使用的@Controller.@RestController.@RequestMapping注解.如果您对Spring MVC不熟悉并且还没有尝试过快速入门案例,建 ...

  6. jprofiler监控wls&was配置

    jprofiler简介: jprofiler的内存视图部分可以提供动态的内存使用状况更新视图和显示关于内存分配状况信息的视图.所有的视图都有几个聚集层并且能够显示现有存在的对象和作为垃圾回收的对象. ...

  7. 一元回归1_基础(python代码实现)

    python机器学习-乳腺癌细胞挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003&u ...

  8. Spring 缓存注解 SpEL 表达式解析

    缓存注解上 key.condition.unless 等 SpEL 表达式的解析 SpEl 支持的计算变量: 1)#ai.#pi.#命名参数[i 表示参数下标,从 0 开始] 2)#result:Ca ...

  9. 网站模板-AdminLTE:AdminLTE

    ylbtech-网站模板-AdminLTE:AdminLTE 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 1. https://adminlte.io/ 1. ...

  10. VSCode - 使用 WSL(Windows Subsystem for Linux)

    一开始我是只将 VSCode 集成的终端改成 WSL 的 Bash,结果发现内置的 GIt 用的还是 Windows 的 Git,Git Hooks 用的 Windows 的环境,上网搜了一下发现有很 ...