可用于 企业网站中的 赞助商、 合作伙伴、 公司产品、 招聘计划等等模块
主要运用的技术有 php +CSS + Jquery插件 flip http://lab.smashup.it/flip/
实现步骤可以大致这样来讲
我们可以看到某个翻牌的div 的源码如下
- <spanstyle="font-size:14px;"><divtitle="Clicktoflip"class="sponsor">
- <divclass="sponsorFlip">
- <imgalt="Moreaboutgoogle"src="img/sponsors/google.png">
- </div>
- <divclass="sponsorData">
- <divclass="sponsorDescription">
- Thecompanythatredefinedwebsearch.
- </div>
- <divclass="sponsorURL">
- <ahref="http://www.google.com/">http://www.google.com/</a>
- </div>
- </div>
- </div></span>
Step 1 我们会首先建立一个 $Sponsor的数组 数组内 含有以下信息 包括logo 网址等内容
- <spanstyle="font-size:14px;">//Eachsponsorisanelementofthe$sponsorsarray:
- $sponsors=array(
- array('facebook','Thebiggestsocial..','http://www.facebook.com/'),
- array('adobe','Theleadingsoftwarede..','http://www.adobe.com/'),
- array('microsoft','Oneofthetopsoftwarec..','http://www.microsoft.com/'),
- array('sony','Aglobalmultibillionelectronics..','http://www.sony.com/'),
- array('dell','Oneofthebiggestcomputerdevelo..','http://www.dell.com/'),
- array('ebay','Thebiggestonlineauctionand..','http://www.ebay.com/'),
- array('digg','Oneofthemostpopularweb2.0..','http://www.digg.com/'),
- array('google','Thecompanythatredefinedw..','http://www.google.com/'),
- array('ea','Thebiggestcomputergamemanufacturer.','http://www.ea.com/'),
- array('mysql','Themostpopularopensourcedat..','http://www.mysql.com/'),
- array('hp','Oneofthebiggestcomputermanufacturers.','http://www.hp.com/'),
- array('yahoo','Themostpopularnetworkofso..','http://www.yahoo.com/'),
- array('cisco','Thebiggestnetworkingandco..','http://www.cisco.com/'),
- array('vimeo','Apopularvideo-centricsocialn..','http://www.vimeo.com/'),
- array('canon','Imagingandopticaltechnologyma..','http://www.canon.com/')
- );
- //Randomizingtheorderofsponsors:
- shuffle($sponsors);</span>
Step2 然后我们会通过遍历整个数组在页面中展示出来
- <spanstyle="font-size:14px;">//Loopingthroughthearray:
- foreach($sponsorsas$company)
- {
- echo'
- <divclass="sponsor"title="Clicktoflip">
- <divclass="sponsorFlip">
- <imgsrc="img/sponsors/'.$company[0].'.png"alt="Moreabout'.$company[0].'"/>
- </div>
- <divclass="sponsorData">
- <divclass="sponsorDescription">
- '.$company[1].'
- </div>
- <divclass="sponsorURL">
- <ahref="'.$company[2].'">'.$company[2].'</a>
- </div>
- </div>
- </div>
- ';
- }</span>
Step 3用到的css 样式如下
- <spanstyle="font-size:14px;">body{
- /*Settingdefaulttextcolor,backgroundandafontstack*/
- font-size:0.825em;
- color:#666;
- background-color:#fff;
- font-family:Arial,Helvetica,sans-serif;
- }
- .sponsorListHolder{
- margin-bottom:30px;
- }
- .sponsor{
- width:180px;
- height:180px;
- float:left;
- margin:4px;
- /*Givingthesponsordivarelativepositioning:*/
- position:relative;
- cursor:pointer;
- }
- .sponsorFlip{
- /*Thesponsordivwillbepositionedabsolutelywithrespect
- toitsparent.sponsordivandfillitinentirely*/
- position:absolute;
- left:0;
- top:0;
- width:100%;
- height:100%;
- border:1pxsolid#ddd;
- background:url("img/background.jpg")no-repeatcentercenter#f9f9f9;
- }
- .sponsorFlip:hover{
- border:1pxsolid#999;
- /*CSS3insetshadow:*/
- -moz-box-shadow:0030px#999inset;
- -webkit-box-shadow:0030px#999inset;
- box-shadow:0030px#999inset;
- }
- /////////////////////////////////////////////////////////////////
- .sponsorFlipimg{
- /*Centeringthelogoimageinthemiddleofthe.sponsorFlipdiv*/
- position:absolute;
- top:50%;
- left:50%;
- margin:-70px00-70px;
- }
- .sponsorData{
- /*Hidingthe.sponsorDatadiv*/
- display:none;
- }
- .sponsorDescription{
- font-size:11px;
- padding:50px10px20px20px;
- font-style:italic;
- }
- .sponsorURL{
- font-size:10px;
- font-weight:bold;
- padding-left:20px;
- }
- .clear{
- /*Thisclassclearsthefloats*/
- clear:both;
- }</span>
Step4 主要运用的jquey 方法如下
- <spanstyle="font-size:14px;">$(document).ready(function(){
- /*ThefollowingcodeisexecutedoncetheDOMisloaded*/
- $('.sponsorFlip').bind("click",function(){
- //$(this)pointtotheclicked.sponsorFlipelement(cachingitinelemforspeed):
- varelem=$(this);
- //data('flipped')isaflagwesetwhenwefliptheelement:
- if(elem.data('flipped'))
- {
- //Iftheelementhasalreadybeenflipped,usetherevertFlipmethod
- //definedbytheplug-intoreverttothedefaultstateautomatically:
- elem.revertFlip();
- //Unsettingtheflag:
- elem.data('flipped',false)
- }
- else
- {
- //Usingtheflipmethoddefinedbytheplugin:
- elem.flip({
- direction:'lr',
- speed:350,
- onBefore:function(){
- //Insertthecontentsofthe.sponsorDatadiv(hidden
- //fromviewwithdisplay:none)intotheclicked
- //.sponsorFlipdivbeforetheflippinganimationstarts:
- elem.html(elem.siblings('.sponsorData').html());
- }
- });
- //Settingtheflag:
- elem.data('flipped',true);
- }
- });
-
});</span>