
这个动画效果有点意思。以前曾经发过类似的效果。
《推荐一个非常有意思的jquery拖拉门效果》
html
- <div class="qitem">
- <a href="http://www.google.com"><img src="image.gif" alt="Test 1" title="" width="140" height="140"/></a>
- <span class="caption"><h4>Title1</h4><p>Description</p></span>
- </div>
css
- body {
- font-family:arial;
- }
- .qitem {
- width:140px;
- height:140px;
- border:4px solid #222;
- margin:5px 5px 5px 0;
- background: url('bg.gif') no-repeat;
- /* required to hide the image after resized */
- overflow:hidden;
- /* for child absolute position */
- position:relative;
- /* display div in line */
- float:left;
- cursor:hand; cursor:pointer;
- }
- .qitem img {
- border:0;
- /* allow javascript moves the img position*/
- position:absolute;
- z-index:200;
- }
- .qitem .caption {
- position:absolute;
- z-index:0;
- color:#ccc;
- display:block;
- }
- .qitem .caption h4 {
- font-size:12px;
- padding:10px 5px 0 8px;
- margin:0;
- color:#369ead;
- }
- .qitem .caption p {
- font-size:10px;
- padding:3px 5px 0 8px;
- margin:0;
- }
- /* Setting for bars */
- .bar1, .bar2, .bar3, .bar4 {
- position:absolute;
- background-repeat: no-repeat;
- z-index:200;
- }
- .clear {
- clear:both;
- }
javascript
- $(document).ready(function() {
- //Custom settings
- var style_in = 'easeOutBounce';
- var style_out = 'jswing';
- var speed_in = 800;
- var speed_out = 300;
- //Top and bottom
- var top = $('.qitem').height() * (-1);
- var bottom = $('.qitem').height();
- $('.qitem').each(function () {
- //retrieve all the details of the image before removing it
- url = $(this).find('a').attr('href');
- img = $(this).find('img').attr('src');
- alt = $(this).find('img').attr('img');
- width = $(this).width() / 4;
- height = $(this).height();
- //remove the image and append 4 div into it
- $('img', this).remove();
- $(this).append('');
- //set the image as background image to all the bars
- $(this).children('div').css('background-image','url('+ img + ')');
- //Divide the image into 4 bars and rebuild the image
- $(this).find('div.bar1').css({top:0, left:0, width:width, height:height, backgroundPosition:'0 0' });
- $(this).find('div.bar2').css({top:0, left:width, width:width, height:height, backgroundPosition:(width*-1) + 'px 0' });
- $(this).find('div.bar3').css({bottom:0, left:width*2, width:width, height:height, backgroundPosition:(width*-2) + 'px 0' });
- $(this).find('div.bar4').css({bottom:0, left:width*3, width:width , height:height, backgroundPosition:(width*-3) + 'px 0' });
- }).hover(function () {
- //Move those bar, 1st and 3rd move upward, 2nd and 4th move downward
- $(this).find('div.bar1').stop(false, true).animate({top:top}, {duration:speed_out, easing:style_out});
- $(this).find('div.bar2').stop(false, true).animate({top:bottom}, {duration:speed_out, easing:style_out});
- $(this).find('div.bar3').stop(false, true).animate({top:top}, {duration:speed_out, easing:style_out});
- $(this).find('div.bar4').stop(false, true).animate({top:bottom}, {duration:speed_out, easing:style_out});
- },
- function () {
- //Back to default position
- $(this).find('div.bar1').stop(false, true).animate({top:0}, {duration:speed_in, easing:style_in});
- $(this).find('div.bar2').stop(false, true).animate({top:0}, {duration:speed_in, easing:style_in});
- $(this).find('div.bar3').stop(false, true).animate({top:0}, {duration:speed_in, easing:style_in});
- $(this).find('div.bar4').stop(false, true).animate({top:0}, {duration:speed_in, easing:style_in});
- }).click (function () {
- //make the whole box clickable
- window.location = $(this).find('a').attr('href');
- });
- });
原文:http://www.queness.com/post/1306/create-a-vertical-sliding-bar-thumbnail-effect-with-jquery

