//首页无缝轮播
;
(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. MongoDB操作:flush()

    flush() 是把缓冲区的数据强行输出,(注意不要和frush()刷新混淆了). 主要用在IO中,即清空缓冲区数据,一般在读写流(stream)的时候,数据是先被读到了内存中,再把数据写到文件中,当 ...

  2. Algorithm lesson final exam

    1.algorithm analysis O B/W/AV/AMOR,混入其他问题,设计+分析 2.传统算法(肯定要考) 1)divide and conquer master therem. rec ...

  3. Oracle数据库表空间查看和更改

    set linesize 200  --设置输出一行字符个数为200 1.查看表空间名称和大小(单位MB) SELECT t.tablespace_name, round(SUM(bytes / (1 ...

  4. android 对话框显示工具类

    这个工具类非常简单,但是将显示dialog的方法统一封装,能够大大减少代码重复 package com.ctbri.weather.utils; import android.app.AlertDia ...

  5. 2018.03.29 python-matplotlib 图表生成

    '''Matplotlib -> 一个python版的matlab绘图接口,以2D为主,支持python,numpy,pandas基本数据结构,高效图标库''' import numpy as ...

  6. C# user32.dll 找窗口 填数据

    工具:SpyLite [DllImport("user32.dll", EntryPoint = "FindWindow")] private extern s ...

  7. 禁止SYS和SYSTEM用户远程登录Oracle oracle的sys和system默认密码

    alter system set remote_login_passwordfile=none scope=spfile; system默认:manager sys默认:change_on_insta ...

  8. flask如何实现https以及自定义证书的制作

    http://blog.csdn.net/yannanxiu/article/details/70672744 http://blog.csdn.net/yannanxiu/article/detai ...

  9. Burp Suite批量网页操作

    1.打开md5解密网站,并输入“21232F297A57A5A743894A0E4A801FC3”,不要点击[Decrypt It!] 1.启动Burp Suite,并设置浏览器代理 3.点击[Dec ...

  10. ELK日志分析之安装

    ELK日志分析之安装 1.介绍: NRT elasticsearch是一个近似实时的搜索平台,从索引文档到可搜索有些延迟,通常为1秒. 集群 集群就是一个或多个节点存储数据,其中一个节点为主节点,这个 ...