首頁 > web前端 > css教學 > 主體

css transform 3D幻燈片特效

高洛峰
發布: 2016-11-24 11:35:19
原創
1381 人瀏覽過

JS

[javascript]
$(function(){ 
    var length = $(".container a").length; 
    var $items = $(".container a"); 
 
    $items.on("transitionend", function(event){ 
        $items.removeClass("trans"); 
    }); 
 
    $(".container a").each(function(index, value){ 
        var $child = $(this); 
        if (index === 0) { 
            $child.addClass("current showing"); 
        } else if (index === 1) { 
            $child.addClass("left showing"); 
        } else if (index == 2) { 
            $child.addClass("out-left"); 
        } else if (index == (length - 2)) { 
            $child.addClass("out-right"); 
        } else if (index === (length - 1)) { 
            $child.addClass("right showing"); 
        } else { 
            $child.addClass("hiding"); 
        };
登入後複製

  
         

        $child.click(function(){ 
            var $item = $(this); 
            //next item   
            var $nextItem = (index === (length - 1)) ?  $items.eq(0) : $items.eq(index + 1); 
            //previous item  
            var $preItem = (index === 0) ? $items.eq(length - 1) : $items.eq(index - 1); 
            var $rightItem; 
            if(index == 0){ 
                $rightItem = $items.eq(length - 2); 
            } else if (index == 1) { 
                $rightItem = $items.eq(length - 1); 
            } else { 
                $rightItem = $items.eq(index - 2); 
            } 
            var $leftItem; 
            if(index == length - 2){ 
                $leftItem = $items.eq(0); 
            } else if (index == length - 1) { 
                $leftItem = $items.eq(1); 
            } else { 
                $leftItem = $items.eq(index + 2); 
            }
登入後複製
            //current item click,return  
            if ($item.hasClass("current")) { 
                return false; 
            } else if ($item.hasClass("left")) { 
                //center move right  
                $preItem.attr("class","trans right showing"); 
                //left move center  
                $item.attr("class","trans current showing"); 
                //right item move out  
                $rightItem.attr("class","trans out-right"); 
                //next move left  
                $nextItem.attr("class","trans left showing"); 
                //left ready  
                $leftItem.attr("class","out-left"); 
            } else if ($item.hasClass("right")) { 
                //center move left  
                $nextItem.attr("class","trans left showing"); 
                //right move center  
                $item.attr("class","trans current showing"); 
                //left item clear  
                $leftItem.attr("class","trans out-left"); 
                //previous move right  
                $preItem.attr("class","trans right showing"); 
                //right ready  
                $rightItem.attr("class","out-right"); 
            }; 
        }); 
    }); 
});
登入後複製
$(function(){
 var length = $(".container a").length;
 var $items = $(".container a");
登入後複製
 $items.on("transitionend", function(event){
  $items.removeClass("trans");
 });
登入後複製
r
 $(".container a").each(function(index, value){
  var $child = $(this);
  if (index === 0) {
   $child.addClass("current showing");
  } else if (index === 1) {
   $child.addClass("left showing");
  } else if (index == 2) {
   $child.addClass("out-left");
  } else if (index == (length - 2)) {
   $child.addClass("out-right");
  } else if (index === (length - 1)) {
   $child.addClass("right showing");
  } else {
   $child.addClass("hiding");
  };
登入後複製


示範


相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板