由于截图不够直观体现其效果。我已将此插件上传到空间。
其实实现起来并不难,先将1张图片复制四份,并设置其为绝对定位,放入四个绝对定位层,四个绝对定位层,分别置于.caption容器层的四角,当然要重新设置下绝对定位层内图片的位置。嘿嘿接下来就是调用JQ的特效来实现其动画效果。
来看其html代码:
- <div class="qitem">
- <a href="http://www.google.com"><img src="1.gif" alt="Test 1" title="" width="126" height="126"/></a>
- <span class="caption"><h4>Night Club</h4><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p></span>
- </div>
来看其javascript代码:
- $(document).ready(function() {
- //Custom settings
- var style_in = 'easeOutBounce';
- var style_out = 'jswing';
- var speed_in = 1000;
- var speed_out = 300;
- //Calculation for corners
- var neg = Math.round($('.qitem').width() / 2) * (-1);
- var pos = neg * (-1);
- var out = pos * 2;
- $('.qitem').each(function () {
- //grab the anchor and image path
- url = $(this).find('a').attr('href');
- img = $(this).find('img').attr('src');
- //remove the image
- $('img', this).remove();
- //append four corners/divs into it
- $(this).append('<DIV class=topLeft></DIV><DIV class=topRight></DIV><DIV class=bottomLeft></DIV><DIV class=bottomRight></DIV>');
- //set the background image to all the corners
- $(this).children('div').css('background-image','url('+ img + ')');
- //set the position of corners
- $(this).find('div.topLeft').css({top:0, left:0, width:pos , height:pos});
- $(this).find('div.topRight').css({top:0, left:pos, width:pos , height:pos});
- $(this).find('div.bottomLeft').css({bottom:0, left:0, width:pos , height:pos});
- $(this).find('div.bottomRight').css({bottom:0, left:pos, width:pos , height:pos});
- }).hover(function () {
- //animate the position
- $(this).find('div.topLeft').stop(false, true).animate({top:neg, left:neg}, {duration:speed_out, easing:style_out});
- $(this).find('div.topRight').stop(false, true).animate({top:neg, left:out}, {duration:speed_out, easing:style_out});
- $(this).find('div.bottomLeft').stop(false, true).animate({bottom:neg, left:neg}, {duration:speed_out, easing:style_out});
- $(this).find('div.bottomRight').stop(false, true).animate({bottom:neg, left:out}, {duration:speed_out, easing:style_out});
- },
- function () {
- //put corners back to the original position
- $(this).find('div.topLeft').stop(false, true).animate({top:0, left:0}, {duration:speed_in, easing:style_in});
- $(this).find('div.topRight').stop(false, true).animate({top:0, left:pos}, {duration:speed_in, easing:style_in});
- $(this).find('div.bottomLeft').stop(false, true).animate({bottom:0, left:0}, {duration:speed_in, easing:style_in});
- $(this).find('div.bottomRight').stop(false, true).animate({bottom:0, left:pos}, {duration:speed_in, easing:style_in});
- }).click (function () {
- //go to the url
- window.location = $(this).find('a').attr('href');
- });
- });

这个挺有意思