// javascript document $(document).ready(function(e) { //图片幻灯片 $("#imgslide").find("li").first().addclass("picshow"); piclen=$("#imgslide").find("li").length; $("#imgbtl").on({ "click":function(){ showpic("l"); }, "mousemove":function(){ $(this).css("background-position","0px 0px") }, "mouseleave":function(){ $(this).css("background-position","-84px 0px") } }) $("#imgbtr").on({ "click":function(){ showpic("r"); }, "mouseover":function(){ $(this).css("background-position","-42px 0px") }, "mouseleave":function(){ $(this).css("background-position","-125px 0px") } }) $("#imgslide").find("dd").on("click",function(){ var index=$(this).index(); var nowpic=$("#imgslide").find("li[class='picshow']").index(); $("#imgslide").find("li").eq(nowpic).removeclass("picshow"); $("#imgslide").find("dd").eq(nowpic).children("img").removeclass("picshow"); $("#imgslide").find("li").eq(index).addclass("picshow"); $("#imgslide").find("dd").eq(index).children("img").addclass("picshow"); }) function showpic(direction){ var index=$("#imgslide").find("li[class='picshow']").index(); $("#imgslide").find("li").eq(index).removeclass("picshow"); $("#imgslide").find("dd").eq(index).children("img").removeclass("picshow"); if(direction=="l"){ if(index==0){//如果是第一张,跳转到最后一张 $("#imgslide").find("li").last().addclass("picshow"); $("#imgslide").find("dd").last().children("img").addclass("picshow"); }else{ $("#imgslide").find("li").eq(index-1).addclass("picshow"); $("#imgslide").find("dd").eq(index-1).children("img").addclass("picshow"); } }else if(direction=="r"){ if(index==piclen-1){//如果是最后一张,跳转到第一张 $("#imgslide").find("li").first().addclass("picshow"); $("#imgslide").find("dd").first().children("img").addclass("picshow"); }else{ $("#imgslide").find("li").eq(index+1).addclass("picshow"); $("#imgslide").find("dd").eq(index+1).children("img").addclass("picshow"); } } } });