您好,欢迎访问一九零五行业门户网

自己用jQuery写了一个图片的马赛克消失效果_jquery

其中的一个效果:
html代码:
复制代码 代码如下:
单击图片,产生效果
插件代码:
复制代码 代码如下:
; (function ($) {
var defaults = {
ani: 4, //动画效果.1.马赛克向中间聚拢,2.马赛克左上角聚拢,3.马赛克拉扯消失,4.原地缩小
delay: 3000, //动画执行时间
url:0,//图片路径
count: [20, 20]//马赛克水平数量,竖直方向数量;数量不能过多,否则计算量太大,计算机执行不了,导致浏览器卡死
}
$.fn.gysmasaike = function (opt) {
opt = $.extend({}, defaults, opt);
if(opt.url==0){alert(没有填写图片路径参数);return;}
var obj = $(this);
if (obj.css(position) == static) obj.css({ position: relative });
obj.css(overflow,hidden);
var objwidth = obj.width();
var objheight = obj.height();
(function (count,url, obj) {
var littleboxwidth = math.floor(objwidth / count[0]);
var littleboxheight = math.floor(objheight / count[1]);
var html = ;
var littleboxleft = littleboxwidth * (-1), littleboxtop = littleboxheight * (-1);
for (var i = 0; i littleboxtop += littleboxheight;
for (var j = 0; j littleboxleft += littleboxwidth;
html += ;
}
littleboxleft = littleboxwidth * (-1);
}
obj.html(html);
})(opt.count,opt.url,obj);
var animation = function (ani, delay, objs) {
var res = function () { }
if (ani == 1) {//马赛克向中间聚拢
res = function () {
objs.animate({ top: objheight / 2, left: objwidth / 2, opacity: 0 }, delay);
settimeout(function(){obj.html();},delay);
}
}
else if (ani == 2) {//碎片向左上角聚拢消失
res = function () {
objs.animate({ left: 0, top: 0, opacity: 0 }, delay); settimeout(function () { obj.html(); }, delay);
}
}
else if (ani == 3) {//拉扯消失
res = function () {
objs.filter(:even).animate({top:-100,left:-100},delay);
objs.filter(:odd).animate({ top: -100, left:900}, delay); settimeout(function(){obj.html();},delay);
}
}
else if (ani == 4) {//
res = function () { objs.animate({ height: 0, width: 0 }, delay);settimeout(function(){obj.html();},delay); }
}
else {
res = function () { objs.animate({ height: 0, width: 0 }, delay);settimeout(function(){obj.html();},delay); }
}
return res;
} (opt.ani, opt.delay, obj.children());
obj.on(click, span, animation);
}
})(jquery);
css代码:
复制代码 代码如下:
.box { width: 1000px; height:600px;}
插件的调用:
复制代码 代码如下:
$(function () {
$(.box).gysmasaike({
count: [10, 15], //马赛克水平数量,竖直方向数量;数量不能过多,否则计算量太大,计算机执行不了,导致浏览器卡死
ani: 4, //动画效果.1.马赛克向中间聚拢,2.马赛克左上角聚拢,3.马赛克拉扯消失,4.原地缩小
delay: 5000, //动画执行时间
url: 1.jpg //图片路径
});
});
其它类似信息

推荐信息