Welcome, Old Sport!

一款简单jQuery动画的图片Over效果

by ilikecss ON 2010/08/09 28048

在这个教程中我将制作一款 图片浏览的动画效果,做网页的朋友们经常会遇到这种问题,一般的图片深浅效果已经不能满足我们的审美观。下面就开始制作。
*我为了美观,边框使用了CSS3所以没有特别使用支持 IE 的浏览效果,请见谅,但这完全不影响动画效果,(框架各浏览器兼容)。

Step1. 创建HTML

<ul class="bannerHolder">
    <li>
    <div class="banner">
        <a href="http://travel.rakuten.co.jp/kaigai/special/hawaii/201003/" target="_blank">
            <img height="125" width="125" alt="The Best Designs" src="images/aloha.jpg" />
        </a>
        <p class="companyInfo">Visit The Best Designs</p>
        <div class="cornerTL"></div>
        <div class="cornerTR"></div>
        <div class="cornerBL"></div>
        <div class="cornerBR"></div>
    </div>
    </li>
    <li>
    <div class="banner">
        <a href="http://ilikecss.com/season1/" target="_blank">
            <img height="125" width="125" alt="The Best Designs" src="images/season1.jpg" />
        </a>
        <p class="companyInfo">Visit The Best Designs</p>
        <div class="cornerTL"></div>
        <div class="cornerTR"></div>
        <div class="cornerBL"></div>
        <div class="cornerBR"></div>
    </div>
    </li>
    <li>
    <div class="banner">
        <a href="http://ilikecss.com/season2/" target="_blank">
            <img height="125" width="125" alt="The Best Designs" src="images/season2.jpg" />
        </a>
        <p class="companyInfo">Visit The Best Designs</p>
        <div class="cornerTL"></div>
        <div class="cornerTR"></div>
        <div class="cornerBL"></div>
        <div class="cornerBR"></div>
    </div>
    </li>
    <li>
    <div class="banner">
        <a href="http://slamdunker.moliyo.com/" target="_blank">
            <img height="125" width="125" alt="The Best Designs" src="images/slamdunker.jpg" />
        </a>
        <p class="companyInfo">Visit The Best Designs</p>
        <div class="cornerTL"></div>
        <div class="cornerTR"></div>
        <div class="cornerBL"></div>
        <div class="cornerBR"></div>
    </div>
    </li>
    <li>
    <div class="banner">
        <a href="http://travel.rakuten.co.jp/select/seagaia/" target="_blank">
            <img height="125" width="125" alt="The Best Designs" src="images/seagaia_miyazaki.jpg" />
        </a>
        <p class="companyInfo">Visit The Best Designs</p>
        <div class="cornerTL"></div>
        <div class="cornerTR"></div>
        <div class="cornerBL"></div>
        <div class="cornerBR"></div>
    </div>
    </li>
</ul>

这里代码告诉我们一个带超链接的图片,图片请自行替换。
class=”companyinfo” 内容就是浏览后的文字,随便替换。

Step2. 创建CSS

.bannerHolder {
	 width: 726px;
	 margin: 20px 0 15px 0;
	 padding: 20px 10px 20px 10px;
	 background-color: #f7f7f7;
	 border: 1px solid #eee;
	 overflow: hidden;
	 -moz-border-radius:12px;
	 -webkit-border-radius:12px;
	 border-radius:12px;
}
.bannerHolder li {
	 list-style: none;
	 display: inline;
}
.banner {
	 position: relative;
	 width: 125px;
	 height: 125px;
	 overflow: hidden;
	 float: left;
	 display: inline;
	 margin: 0 10px
}
.banner img {
	 display: block;
	 border: none;
}
.banner div {
	 position: absolute;
	 z-index: 100;
	 background-color: #222;
	 width: 60px;
	 height: 60px;
	 cursor: pointer;
	 -moz-border-radius:100px;
	 -webkit-border-radius:100px;
	 border-radius:100px;
}
.banner .cornerTL { left:-63px; top:-63px; }
.banner .cornerTR { right:-63px; top:-63px; }
.banner .cornerBL { left:-63px; bottom:-63px; }
.banner .cornerBR { right:-63px; bottom:-63px; }
.banner p {
	 display: none;	/* hidden by default */
	 left: 0;
	 top: 57px;
	 width: 100%;
	 z-index: 200;
	 position: absolute;
	 font-family: Tahoma, Arial, Helvetica, sans-serif;
	 color: #FFF;
	 font-size: 11px;
	 text-align: center;
	 cursor: pointer;
}

Step3. 插入jQuery和脚本包

$(document).ready(function(){

	// Lowering the opacity of all slide in divs
	$('.banner div').css('opacity',0.4);

	// Using the hover method 
	$('.banner').hover(function(){

		// Executed on mouseenter
		
		var el = $(this);
		
		// Find all the divs inside the banner div,
		// and animate them with the new size
		
		el.find('div').stop().animate({width:200,height:200},'slow',function(){
			// Show the "Visit Company" text:
			el.find('p').fadeIn('fast');
		});

	},function(){

		// Executed on moseleave

		var el = $(this);
		
		// Hiding the text
		el.find('p').stop(true,true).hide();
		
		// Animating the divs
		el.find('div').stop().animate({width:60,height:60},'fast');

	}).click(function(){
		
		// When clicked, open a tab with the address of the hyperlink
		
		window.open($(this).find('a').attr('href'));
		
	});
});
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
2条评论
  1. #1

    小蝴蝶说道:

    我的目标是…挖坟沙发!




TOP