对于具有不同CSS的页面,barba.js过渡不会过渡

时间:2020-08-09 07:34:03

标签: javascript html css barbajs

我在页面过渡上跟随了devEd tutorial,我有两个页面的CSS完全不同。在他的教程中,他为两个页面使用了相同的CSS。当我转到第二页时,URL更改,但页面保持不变。我在控制台日志中检查了第二页的响应,有一个xhr请求显示响应预览,这意味着它正在获取页面,并且转换问题与我的div或css转换有关。

主页 html characters are more than the limit, here is the link to it

主页的CSS(flexy.css)

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Montserrat;
}

.navbar {
    display: flex;
    align-items: center;
    padding: 5px;
}

nav {
    flex: 1;
    text-align: right;
}

nav ul {
    display: inline-block;
    list-style-type: none;
}

nav ul li {
    display: inline-block;
    margin-right: 70px;
}

a {
    text-decoration: none;
    font-style: normal;
    font-weight: 500;
    font-size: 14px;
    line-height: 17px;
    color: #63BA86;
    font-family: Montserrat;
    transition: transform .6s cubic-bezier(.77, 0, .175, 1);
    transition-property: transform;
    transition-duration: 0.6s;
    transition-timing-function: cubic-bezier(0.77, 0, 0.175, 1);
    transition-delay: 0s;
}

ay:hover::after {
    transform-origin: left center;
    transform: translate3d(0, 0, 0) scaleX(1);
}

p {
    color: #555;
}

.logo {
    font-style: normal;
    font-weight: 500;
    font-size: 18px;
    line-height: 17px;
    color: #63BA86;
    margin: 10px;
    font-family: Montserrat;
}

.container {
    max-width: 1300px;
    margin: auto;
    padding-left: 10px;
    padding-right: 10px;
}

h1.st {
    font-family: Montserrat;
    font-style: normal;
    font-weight: 800;
    color: #63BA86;
    padding-left: 50px;
    line-height: 44px;
}

h2.low {
    font-family: Montserrat;
    font-style: normal;
    font-weight: 400;
    font-size: 19px;
    line-height: 23px;
    color: #63BA86;
}

.row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: space-around;
}

.rowe {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
}

.roww {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: space-around;
}

.col-2 {
    flex-basis: 50%;
    min-width: 400px;
    padding: 0 50px;
}

.col-2w {
    flex-basis: 50%;
    min-width: 400px;
    padding: 0 50px;
}

.col-2w img {
    max-width: 100%;
    padding: 50px 0;
}

.col-2 svg {
    max-width: 100%;
    padding: 50px 0;
}

.col-2right {
    flex-basis: 50%;
    min-width: 300px;
    max-width: 100%;
    padding: 50px 0;
}

.btn {
    display: inline-block;
    border-radius: 30px;
    background: #67E298;
    margin: 30px 0;
    padding: 15px 30px;
    color: white;
    margin-left: 50px;
    transition: background 0.5s;
}

.header {
    background: rgba(235, 255, 243, 0.5);
}

.header .row {
    margin-top: 100px;
}

.btn:hover {
    background: #51BB7B;
}

.eature-item {
    background-color: rgba(180, 236, 219, 0.52);
    width: 200px;
    height: 200px;
    margin: 60px;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container2 {
    background: rgba(235, 255, 243, 0.59);
}

.box {
    width: 244px;
    height: 368px;
    background: #FFFFFF;
    border-radius: 15px;
    margin: 30px;
}

h2.boxx {
    font-family: Montserrat;
    font-style: normal;
    font-weight: normal;
    font-size: 10px;
    line-height: 22px;
    color: #2C2F45;
    margin-top: 42px;
    margin-left: 18px;
    margin-right: 18px;
}

h2.top {
    font-family: Montserrat;
    font-style: normal;
    font-weight: bold;
    font-size: 18px;
    line-height: 22px;
    color: #2E7B4D;
    margin-top: 15px;
    margin-left: 18px;
}

h2.butm {
    font-family: Montserrat;
    font-style: normal;
    font-weight: 500;
    font-size: 17px;
    line-height: 22px;
    color: #2E7B4D;
    margin-top: 140px;
    margin-left: 18px;
}

.slide-in {
    animation: slide-in 0.5s ease forwards;
}

@keyframes slide-in {
    from {
        transform: translateX(100%);
        visibility: visible;
    }
    to {
        transform: translateX(0%);
    }
}

app.js

Barba.Pjax.start()



var FadeTransition = Barba.BaseTransition.extend({
    start: function() {
        /**
         * This function is automatically called as soon the Transition starts
         * this.newContainerLoading is a Promise for the loading of the new container
         * (Barba.js also comes with an handy Promise polyfill!)
         */

        // As soon the loading is finished and the old page is faded out, let's fade the new page
        Promise
            .all([this.newContainerLoading, this.fadeOut()])
            .then(this.fadeIn.bind(this));
    },

    fadeOut: function() {
        /**
         * this.oldContainer is the HTMLElement of the old Container
         */
        this.oldContaineer
    },

    fadeIn: function() {
        this.newContainer.classList.add("slide-in");
    }
});

/**
 * Next step, you have to tell Barba to use the new Transition
 */

Barba.Pjax.getTransition = function() {
    /**
     * Here you can use your own logic!
     * For example you can use different Transition based on the current page or link...
     */

    return FadeTransition;
};

第二页

<!DOCTYPE html>
<html>

<head>

    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>Home - Brand</title>
    <link rel="stylesheet" href="dash.css">

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;200;300;400;500;600;700&display=swap" rel="stylesheet">
    <script src="https://code.iconify.design/1/1.0.6/iconify.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/barba.js/1.0.0/barba.js"></script>
</head>

<body>
    <div id="barba-wrapper">
        <div class="barba-container">
            <div class="diff">h2</div>
        </div>
    </div>
    <script src="app.js"></script>
</body>

</html>

第二个CSS(dash.css)

        * {
            margin: 0;
            padding: 0;
            outline: none;
        }
        
        body {
            font-family: Montserrat;
            text-align: justify;
            overflow-x: hidden;
            height: 1500px;
            color: #666;
        }
        
        .content {}
        
        .content p {
            margin-bottom: 50px;
        }
        
        .wrapper {
            position: relative;
            left: 0;
        }
        
        #menu {
            position: fixed;
            width: 240px;
            height: 100%;
            top: 0;
            left: -240px;
            background-color: #63BA86;
            z-index: 1000;
            overflow: auto;
        }
        
        #menu,
        .wrapper {
            transition: all 0.3s ease;
        }
        
        #menu,
        ul {
            list-style: none;
        }
        
        #menu,
        ul h1 {
            text-align: center;
            color: white;
            font-size: 16px;
            cursor: default;
        }
        
        #menu,
        ul li:first-child {}
        
        #menu,
        ul li {
            padding: 15px 0 15px 0px;
            text-align: left;
        }
        
        #menu ul li:hover {
            background-color: wheat;
            border-radius: 20px;
        }
        
        #menu,
        ul li a {
            color: white;
            text-decoration: none;
            font-size: 20px;
            font-family: Montserrat;
            font-weight: 400;
        }
        
        #menu.menu-open {
            left: 0px;
        }
        
        .menu-push {
            left: 240px;
        }
        
        .menu-btn {
            color: cadetblue;
            border: none;
            position: fixed;
            padding: 30px;
            background-color: transparent;
            cursor: pointer;
        }
        
        .boxyy ul {
            display: flex;
            flex-wrap: wrap;
            padding-left: 80px;
        }
        
        .boxyy ul li {
            list-style: none;
            width: 185px;
            height: 150px;
            background: #FFFFFF;
            box-shadow: 0px 0px 4px 1px rgba(0, 0, 0, 0.25);
            border-radius: 20px;
            margin-right: 150px;
            margin-bottom: 50px;
        }
        
        .bas {
            flex-basis: 40%;
        }
        
        .iconn {
            text-align: center;
            margin-top: 5px;
        }
        
        h1.buto {
            font-family: Montserrat;
            font-style: normal;
            font-weight: bold;
            font-size: 15px;
            line-height: 37px;
            color: #63BA86;
            text-align: center;
        }
        
        h1.lau {
            font-family: Montserrat;
            font-style: normal;
            font-weight: normal;
            font-size: 15px;
            line-height: 30px;
            color: #3D8D5D;
        }
        
        .bttn {
            background: #63BA86;
            border-radius: 5px;
            width: 70px;
            height: 30px;
            margin-left: 50px;
        }
        
        h1.laud {
            font-family: Montserrat;
            font-style: normal;
            font-weight: normal;
            font-size: 12px;
            line-height: 30px;
            color: white;
            text-align: center;
        }
        
        .navbar {
            display: flex;
            align-items: center;
            padding: 5px;
        }
        
        .navv {
            flex: 1;
            text-align: right;
        }
        
        .navv ul {
            display: inline-block;
            list-style-type: none;
        }
        
        .navv ul li {
            display: inline-block;
            margin-right: 70px;
        }
        
        .container {
            max-width: 1300px;
            margin: auto;
            padding-left: 10px;
            padding-right: 10px;
        }
        
        .header {
            background: rgba(235, 255, 243, 0.5);
        }
        
        .header .row {
            margin-top: 100px;
        }
        
        h1.avail {
            font-family: Montserrat;
            font-style: normal;
            font-weight: normal;
            font-size: 18px;
            line-height: 59px;
            color: #63BA86;
            padding-left: 70px;
        }
        
        img.round {
            border-radius: 50%;
        }
        
        .slide-in {
            animation: slide-in 0.5s ease forwards;
        }
        
        @keyframes slide-in {
            from {
                transform: translateX(100%);
                visibility: visible;
            }
            to {
                transform: translateX(0%);
            }
        }

0 个答案:

没有答案