jquery做一个小的轮播插件---有BUG,后续修改
//首页无缝轮播
;
(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,后续修改的更多相关文章
- 使用jQuery做简单的图片轮播效果
一.本特效主要用到的前端知识点 CSS中绝对定位(absolute)CSS实现垂直居中jQuery中简单的淡入淡出动画效果(fadeIn,fadeOut)定时器(setInterval,clear ...
- 实现一个3D图片轮播插件 —— 更新版
前言: 前段时间写下了之前那篇 3D图片轮播效果,后来发现了 Pedro Botelho 写的jquery.gallery.js ,于是重新修改了自己的这个图片轮播,使之可以成为一个插件来使用 ...
- jquery制作一个简单的轮播
效果图: 演示地址: http://ae6623.cn/demo/slider/index.html 思路: 利用css的定位属性 left 进行调整图片的显示,每次点击上一页下一页按钮的时候,-图片 ...
- (转)jQuery轻量级响应式图片轮播插件ResponsiveSlides.js(仅1kb)也可以做纯文本轮播
ResponsiveSlides.js是一个展示同一容器内图片的轻量级响应式jQuery幻灯片插件(tiny responsive slideshow jQuery plugin).它支持包括IE6在 ...
- 图片轮播插件-carouFredSel
carouFredSel图片轮播插件基于Jquery,比较常规的轮播插件,支持滚轮及键盘左右按键,加入其它插件可实现更加复杂的特效. 主页地址:http://caroufredsel.dev7stud ...
- 关于最近在做的一个js全屏轮播插件
最近去面试了,对方要求我在一个星期内用原生的js代码写一个全屏轮播的插件,第一想法就是跟照片轮播很相似,只是照片轮播是有定义一个宽高度大小已经确定了的容器用来存储所有照片,然后将照片全部左浮动,利用m ...
- 自己写的一个jQuery轮播插件
大概是四月初开始写的,中间停了有一个月吧.这是我在Github的第一个项目.项目地址:https://github.com/linzb93/jquery.slide.js. 轮播应该是最好写的插件了, ...
- Javascript和jQuery WordPress 图片轮播插件, 内容滚动插件,前后切换幻灯片形式显示
用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美的图片轮播效果,希望这些插件 ...
- PgwSlideshow-基于Jquery的图片轮播插件
0 PgwSlideshow简介 PgwSlideshow是一款基于Jquery的图片轮播插件,基本布局分为上下结构,上方为大图轮播区域,用户可自定义图片轮播切换的间隔时间,也可以通过单击左右方向按键 ...
随机推荐
- Tire树简介
又称单词查找树,Trie树,是一种树形结构,是一种哈希树的变种. 典型应用:用于统计,排序和保存大量的字符串(但不仅限于字符串),所以经常被搜索引擎系统用于文本词频统计. 它的优点是:利用字符串的公共 ...
- NOIP2016考前做题(口胡)记录
NOIP以前可能会持续更新 写在前面 NOIP好像马上就要到了,感觉在校内训练里面经常被虐有一种要滚粗的感觉(雾.不管是普及组还是提高组,我都参加了好几年了,结果一个省一都没有,今年如果还没有的话感觉 ...
- linux服务器在线测速
cd /tmpwget https://raw.github.com/sivel/speedtest-cli/master/speedtest.py或者wget https://raw.githubu ...
- java跨越请求实例
使用Access-Control-Allow-Origin解决跨域 什么是跨域 当两个域具有相同的协议(如http), 相同的端口(如80),相同的host(如www.google.com),那么我们 ...
- ES6注
1.Promise构造函数 //resolve(成功),reject(失败)两个参数 function runAsync(){ var p = new Promise(function(resolve ...
- switch 失效
switch 开关失效无法切换,可以关闭,无法开启. 发现问题点 require-table.js 中toggle value的数据类型不是 number 导致 (value ? no : yes ...
- Latex常用公式整理
目录 常用 常用数学公式 常用希腊字母 说明:博客园中的Latex编辑是以$ latex公式 $,为边界. 1.常用 描述 Latex公式 表达式 下标 x_2 x2 上标 x^2 x2 分数 \f ...
- ERROR:imshow、Mat、waitkey找不到标识符(opencv)
可以发现imshow.Mat.waitkey这三个都是opencv相关的. 在添加了相关库文件后还是有问题. #include "stdafx.h" #include <st ...
- Object.freeze与 Object.seal的区别
Object.freeze()冻结一个对象.不能添加新的属性,不能删除已有属性,不能修改该对象已有属性的可枚举性.可配置性.可写性,以及不能修改已有属性的值.冻结一个对象后该对象的原型也不能被修改. ...
- Service层获取HttpServletRequest request
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/liuyunshengsir/article/details/78183058HttpServletR ...