如何添加整页转换? (见说明)

时间:2013-11-28 16:41:29

标签: jquery html5 css3 transition

我创建了一个包含HTML5和CSS3的网站,我正在考虑只有一个带有背景图像的首页,以及用箭头或“进入网站”按钮进入网站的选项。

但是不是点击按钮而是将你带到另一个html文件/新网站(就像点击标准导航中的链接一样)我希望它从底部淡入 - 就像'从底部淡出'选项这里http://tympanus.net/Development/PageTransitions/ - 到同一个html文档中的新页面(普通首页),因此访问者不必加载新页面。

任何?

(PS。我在上面的链接中试过了这个功能,但无法让它工作)

1 个答案:

答案 0 :(得分:1)

你需要Modernizr,pagetransitions.js和animations.css来获得相同的效果,如果你只需要'淡入淡出'你可以使用这个修改过的pagetransitions.js

var PageTransitions = (function() {

    var $main = $( '#pt-main' ),
            $pages = $main.children( 'div.pt-page' ),
            $iterate = $( '#iterateEffects' ),
            animcursor = 1,
            pagesCount = $pages.length,
            current = 0,
            isAnimating = false,
            endCurrPage = false,
            endNextPage = false,
            animEndEventNames = {
                    'WebkitAnimation' : 'webkitAnimationEnd',
                    'OAnimation' : 'oAnimationEnd',
                    'msAnimation' : 'MSAnimationEnd',
                    'animation' : 'animationend'
            },
            animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ],
            // support css animations
            support = Modernizr.cssanimations;

    function init() {
            $pages.each( function() {
                    var $page = $( this );
                    $page.data( 'originalClassList', $page.attr( 'class' ) );
            } );
            $pages.eq( current ).addClass( 'pt-page-current' );
            $iterate.on( 'click', function() {
                    if( isAnimating ) {
                            return false;
                    }
                    nextPage( animcursor );
                    ++animcursor;
            } );
    }

    function nextPage(options ) {
            var animation = (options.animation) ? options.animation : options;
            if( isAnimating ) {
                    return false;
            }
            isAnimating = true;
            var $currPage = $pages.eq( current );
            if(options.showPage){
                    if( options.showPage < pagesCount - 1 ) {
                            current = options.showPage;
                    }
                    else {
                        return false;
                    }
            }
            else{
                    if( current < pagesCount - 1 ) {
                            ++current;
                    }
                    else {
                         return false;
                    }
            }
            var $nextPage = $pages.eq( current ).addClass( 'pt-page-current' ),
                    outClass = '', inClass = '';
              outClass = 'pt-page-fade';
              inClass = 'pt-page-moveFromBottom pt-page-ontop';
            $currPage.addClass( outClass ).on( animEndEventName, function() {
                    $currPage.off( animEndEventName );
                    endCurrPage = true;
                    if( endNextPage ) {
                            onEndAnimation( $currPage, $nextPage );
                    }
            } );
            $nextPage.addClass( inClass ).on( animEndEventName, function() {
                    $nextPage.off( animEndEventName );
                    endNextPage = true;
                    if( endCurrPage ) {
                            onEndAnimation( $currPage, $nextPage );
                    }
            } );
            if( !support ) {
                    onEndAnimation( $currPage, $nextPage );
            }

    }

    function onEndAnimation( $outpage, $inpage ) {
            endCurrPage = false;
            endNextPage = false;
            resetPage( $outpage, $inpage );
            isAnimating = false;
    }

    function resetPage( $outpage, $inpage ) {
            $outpage.attr( 'class', $outpage.data( 'originalClassList' ) );
            $inpage.attr( 'class', $inpage.data( 'originalClassList' ) + ' pt-page-current' );
    }
    init();
    return { 
            init : init,
            nextPage : nextPage,
    };

})();    

CSS

/* move from / to  */
.pt-page-moveFromBottom {
    -webkit-animation: moveFromBottom .6s ease both;
    -moz-animation: moveFromBottom .6s ease both;
    animation: moveFromBottom .6s ease both;
}
/* fade */
.pt-page-fade {
    -webkit-animation: fade .7s ease both;
    -moz-animation: fade .7s ease both;
    animation: fade .7s ease both;
}

/* move from / to  */
@-webkit-keyframes moveFromBottom {
    from { -webkit-transform: translateY(100%); }
}
@-moz-keyframes moveFromBottom {
    from { -moz-transform: translateY(100%); }
}
@keyframes moveFromBottom {
    from { transform: translateY(100%); }
}

/* fade */

@-webkit-keyframes fade {
    to { opacity: 0.3; }
}
@-moz-keyframes fade {
    to { opacity: 0.3; }
}
@keyframes fade {
    to { opacity: 0.3; }
}

*, *:after, *:before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
body, html { font-size: 100%; padding: 0; margin: 0;}

/* Clearfix hack by Nicolas Gallagher: http://nicolasgallagher.com/micro-clearfix-hack/ */
.clearfix:before, .clearfix:after { content: " "; display: table; }
.clearfix:after { clear: both; }

body {
    font-family: 'Lato', Calibri, Arial, sans-serif;
    color: #fff;
    background: #333;
    overflow: hidden;
}
html, body { height: 100%; }
.pt-perspective {
    position: relative;
    width: 100%;
    height: 100%;
    -webkit-perspective: 1200px;
    -moz-perspective: 1200px;
    perspective: 1200px;
}

.pt-page {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    visibility: hidden;
    overflow: hidden;
    -webkit-backface-visibility: hidden;
    -moz-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translate3d(0, 0, 0);
    -moz-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-transform-style: preserve-3d;
    -moz-transform-style: preserve-3d;
    transform-style: preserve-3d;
}

.pt-page-current,
.no-js .pt-page {
    visibility: visible;
    z-index: 1;
}

.no-js body {
    overflow: auto;
}

.pt-page-ontop {
    z-index: 999;
}

.pt-page-1 {
    background: #0ac2d2;
}

.pt-page-2 {
    background: #7bb7fa;
}

.no-js .pt-triggers {
    display: none;
}    

html

<div id="pt-main" class="pt-perspective">
    <div class="pt-page pt-page-1">     
         <h1><span>A collection of</span><strong>Page</strong> Transitions</h1>
         <div class="pt-triggers">
             <button id="iterateEffects" class="pt-touch-button">Show next page transition</button>                      
         </div>
    </div>
    <div class="pt-page pt-page-2">
        <h1><span>A collection of</span><strong>Page</strong> Transitions</h1>
    </div>
</div>    

http://jsfiddle.net/7tjgy/