Home  >  Article  >  Web Front-end  >  An image switching effect based on jquery_jquery

An image switching effect based on jquery_jquery

WBOY
WBOYOriginal
2016-05-16 18:23:51912browse

The following code is a reference for friends who are learning jquery
An image switching effect based on jquery_jquery
html code:

code

Copy code The code is as follows:






< ;/div>


javascript:


Copy code The code is as follows:

$(document).ready(function(){
var $warp = $("#warp");
$warp.IsRunning = false;
var seconds = 500;
$warp.children("img").click(function(){
if($warp.IsRunning){return;}
$warp.IsRunning = true;
var $imgs = $("#warp").children("img");

$imgs.eq(2).css("marginTop","63px").animate({marginTop :"0px"},{duration:seconds});
$imgs.eq(0).css({position:"absolute",opacity:"0.5"}).animate({width:"108px", height:"57px",left:"372px",top:"126px",opacity:"1"},{duration:seconds});
//$imgs.eq(1).css({position: "absolute",left:"372px",top:"6px",opacity:"0.2"});

$imgs.eq(1).css({position:"absolute",left:" 372px",top:"6px",opacity:"0.2",clear:"none"}).animate({width:"360px", height:"190px",left:"-9px",top:"-5px ",opacity:"1"},{duration:seconds,complete:function(){
$imgs.eq(0).appendTo($("#warp"));
$imgs.eq( 0).removeAttr("style").removeClass("imgBig").addClass("imgLittle");
$imgs.eq(1).removeAttr("style").removeClass("imgLittle").addClass ("imgBig");
$warp.IsRunning = false;
}});

});
});


css code:
Copy code The code is as follows:

.warp{width:487px; height: 194px; overflow:hidden;border:solid 1px #ccc;position:relative; top:0px; left:0px; background-color:#fafafa}
.warp img{border-width:0px;cursor:pointer;position :relative; top:0px; left:0px}
.imgBig{float:left; width:360px; height:190px;padding:2px;}
.imgLittle{float:right; width:108px; height: 57px;padding:6px 5px 0 10px;clear:right}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn