Skip to main content

GreenSock Tutorial - How To Create A Simple Image Slideshow ?

 GreenSock Tutorial - How To Create A Simple Image Slideshow 





SOURCE CODE




HTML SOURCE_CODE:-


<!DOCTYPE html>
<html lang="en" class="no-js">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Crossroads Slideshow | Codrops</title>
        
        <link rel="stylesheet" type="text/css" href="css/base.css" />
        <script>document.documentElement.className="js";var supportsCssVars=function(){var e,t=document.createElement("style");return t.innerHTML="root: { --tmp-var: bold; }",document.head.appendChild(t),e=!!(window.CSS&&window.CSS.supports&&window.CSS.supports("font-weight","var(--tmp-var)")),t.parentNode.removeChild(t),e};supportsCssVars()||alert("Please view this demo in a modern browser that supports CSS Variables.");</script>
    </head>
    <body class="loading">
        <main>
            <div class="content">
                <article class="content__item">
                    <div class="img-wrap img-wrap--content">
                        <div class="img img--content" style="background-image: url(img/1.jpg);"></div>
                    </div>
                    <header class="content__item-header">
                        <span class="content__item-header-meta">New York City, March 24</span>
                        <h2 class="content__item-header-title">kani</h2>
                    </header>
                    <div class="content__item-copy">
                        <p class="content__item-copy-text">
                        In the gloomy domed livingroom of the tower Buck Mulligan’s gowned form
                        moved briskly to and fro about the hearth, hiding and revealing its
                        yellow glow. Two shafts of soft daylight fell across the flagged floor
                        from the high barbacans: and at the meeting of their rays a cloud of
                        coalsmoke and fumes of fried grease floated, turning.
                        </p>
                        <a href="#" class="content__item-copy-more">more +</a>
                    </div>
                </article>
                <article class="content__item">
                    <div class="img-wrap img-wrap--content">
                        <div class="img img--content" style="background-image: url(img/2.jpg);"></div>
                    </div>
                    <header class="content__item-header">
                        <span class="content__item-header-meta">Acapulco, March 25</span>
                        <h2 class="content__item-header-title">Bob</h2>
                    </header>
                    <div class="content__item-copy">
                        <p class="content__item-copy-text">
                        The key scraped round harshly twice and, when the heavy door had been
                        set ajar, welcome light and bright air entered. Haines stood at the
                        doorway, looking out. Stephen haled his upended valise to the table and
                        sat down to wait. Buck Mulligan tossed the fry on to the dish beside
                        him. Then he carried the dish and a large teapot over to the table, set
                        them down heavily and sighed with relief.
                        </p>
                        <a href="#" class="content__item-copy-more">more +</a>
                    </div>
                </article>
                <article class="content__item">
                    <div class="img-wrap img-wrap--content">
                        <div class="img img--content" style="background-image: url(img/3.jpg);"></div>
                    </div>
                    <header class="content__item-header">
                        <span class="content__item-header-meta">Brisbane, March 26</span>
                        <h2 class="content__item-header-title">Canon</h2>
                    </header>
                    <div class="content__item-copy">
                        <p class="content__item-copy-text">
                        Stephen listened in scornful silence. She bows her old head to a voice
                        that speaks to her loudly, her bonesetter, her medicineman: me she
                        slights. To the voice that will shrive and oil for the grave all there
                        is of her but her woman’s unclean loins, of man’s flesh made not in
                        God’s likeness, the serpent’s prey.
                        </p>
                        <a href="#" class="content__item-copy-more">more +</a>
                    </div>
                </article>
                <article class="content__item">
                    <div class="img-wrap img-wrap--content">
                        <div class="img img--content" style="background-image: url(img/4.jpg);"></div>
                    </div>
                    <header class="content__item-header">
                        <span class="content__item-header-meta">Berlin, March 27</span>
                        <h2 class="content__item-header-title">Hill</h2>
                    </header>
                    <div class="content__item-copy">
                        <p class="content__item-copy-text">
                        And putting on his stiff collar and rebellious tie he spoke to them,
                        chiding them, and to his dangling watchchain. His hands plunged and
                        rummaged in his trunk while he called for a clean handkerchief. God,
                        we’ll simply have to dress the character. I want puce gloves and green
                        boots. Contradiction.
                        </p>
                        <a href="#" class="content__item-copy-more">more +</a>
                    </div>
                </article>
            </div>
            <div class="revealer">
                <div class="revealer__inner"></div>
            </div>
            <div class="grid grid--slideshow">
                <figure class="grid__item grid__item--slide">
                    <span class="number">01</span>
                    <div class="img-wrap">
                        <div class="img" style="background-image: url(img/1.jpg);"></div>
                    </div>
                    <figcaption class="caption">New York City, March 24</figcaption>
                </figure>
                <figure class="grid__item grid__item--slide">
                    <span class="number">02</span>
                    <div class="img-wrap">
                        <div class="img" style="background-image: url(img/2.jpg);"></div>
                    </div>
                    <figcaption class="caption">Acapulco, March 25</figcaption>
                </figure>
                <figure class="grid__item grid__item--slide">
                    <span class="number">03</span>
                    <div class="img-wrap">
                        <div class="img" style="background-image: url(img/3.jpg);"></div>
                    </div>
                    <figcaption class="caption">Brisbane, March 26</figcaption>
                </figure>
                <figure class="grid__item grid__item--slide">
                    <span class="number">04</span>
                    <div class="img-wrap">
                        <div class="img" style="background-image: url(img/4.jpg);"></div>
                    </div>
                    <figcaption class="caption">Berlin, March 27</figcaption>
                </figure>
                <div class="titles-wrap">
                    <div class="grid grid--titles">
                        <h3 class="grid__item grid__item--title">Kani</h3>
                        <h3 class="grid__item grid__item--title">Bob</h3>
                        <h3 class="grid__item grid__item--title">Canon</h3>
                        <h3 class="grid__item grid__item--title">Hill</h3>
                    </div>
                </div>
                <div class="grid grid--interaction">
                    <div class="grid__item grid__item--cursor grid__item--left"></div>
                    <div class="grid__item grid__item--cursor grid__item--center"></div>
                    <div class="grid__item grid__item--cursor grid__item--right"></div>
                </div>
            </div>
            <div class="frame">
                                    <div class="frame__mode" role="radiogroup">
                        <div class="frame__mode-item frame__mode-item--dark">
                            <input id="mode-1" type="radio" name="mode" class="frame__mode-input"></input>
                            <label class="frame__mode-label" for="mode-1">Dark mode</label>
                        </div>
                        <div class="frame__mode-item">
                            <input id="mode-2" type="radio" name="mode" class="frame__mode-input" checked></input>
                            <label class="frame__mode-label frame__mode-label--light" for="mode-2">Light mode</label>
                        </div>
                    </div>
                </div>
            </div><!-- /frame -->
        </main>
        <script src="js/imagesloaded.pkgd.min.js"></script>
        <script src="js/charming.min.js"></script>
        <script src="js/TweenMax.min.js"></script>
        <script src="js/demo.js"></script>
    </body>
</html>




CSS SOURCE_CODE:-

article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block;}audio,canvas,video{display:inline-block;}audio:not([controls]){display:none;height:0;}[hidden]{display:none;}html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;}body{margin:0;}a:focus{outline:thin dotted;}a:active,a:hover{outline:0;}h1{font-size:2em;margin:0.67em 0;}abbr[title]{border-bottom:1px dotted;}b,strong{font-weight:bold;}dfn{font-style:italic;}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0;}mark{background:#ff0;color:#000;}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em;}pre{white-space:pre-wrap;}q{quotes:"\201C" "\201D" "\2018" "\2019";}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sup{top:-0.5em;}sub{bottom:-0.25em;}img{border:0;}svg:not(:root){overflow:hidden;}figure{margin:0;}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em;}legend{border:0;padding:0;}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0;}button,input{line-height:normal;}button,select{text-transform:none;}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer;}button[disabled],html input[disabled]{cursor:default;}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0;}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none;}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}textarea{overflow:auto;vertical-align:top;}table{border-collapse:collapse;border-spacing:0;}
*,
*::after,
*::before {
    box-sizingborder-box;
}

.debug {
    transformscale(0.5);
}

.debug * {
    outline1px solid red;
    opacity0.9;
}

htmlbody {
    height100%;
}

:root {
    font-size15px;
}

body {
    --color-text#5d5d5d;
    --color-bg#e6e6ea;
    --color-link#838288;
    --color-link-hover#000;
    --color-number#000;
    --color-title#000;
    --color-caption#000;
    --color-content#000;
    --color-content-bgvar(--color-bg);
    --color-reveal-bgvar(--color-bg);
    colorvar(--color-text);
    background-colorvar(--color-bg);
    font-family: transat-text, sans-serif;
    -webkit-font-smoothingantialiased;
    -moz-osx-font-smoothinggrayscale;
    text-renderingoptimizeLegibility;
}

.dark-mode {
    --color-text#424242;
    --color-bg#101010;
    --color-link:  #fadb2a;
    --color-link-hover#fff;
    --color-number#484848;
    --color-title#fadb2a;
    --color-caption#484848;
    --color-content#dadada;
    --color-content-title:#fadb2a;
    --color-content-meta#fff;
}

/* Page Loader */
.js .loading::before {
    content'';
    positionfixed;
    z-index100000;
    top0;
    left0;
    width100%;
    height100%;
    backgroundvar(--color-bg);
}

.js .loading::after {
    content'';
    positionfixed;
    z-index100000;
    top50%;
    left50%;
    width60px;
    height60px;
    margin-30px 0 0 -30px;
    pointer-eventsnone;
    border-radius50%;
    opacity0.4;
    backgroundvar(--color-link);
    animation: loaderAnim 0.7s linear infinite alternate forwards;
}

@keyframes loaderAnim {
    to {
        opacity1;
        transformscale3d(0.5,0.5,1);
    }
}

a {
    text-decorationnone;
    colorvar(--color-link);
    outlinenone;
}

a:hover,
a:focus {
    colorvar(--color-link-hover);
    outlinenone;
}

main {
    positionrelative;
    min-height100vh;
}

.frame {
    padding3rem 5vw 0;
    text-aligncenter;
    positionrelative;
    z-index100;
}

.frame__title {
    font-size1rem;
    margin0 0 1rem;
}

.frame__links a {
    margin0 0.5rem;
}

.frame__mode {
    margin1rem auto;
    displayflex;
    justify-contentcenter;
}

.frame__mode-item {
    positionrelative;
    width20px;
    height20px;
    margin0 0.25rem;
    pointer-eventsauto;
    border-radius50%;
    background#fff;
    overflowhidden;
    border1px solid var(--color-text);
}


.frame__mode-item--dark {
    background#000;
}

.frame__mode-label,
.frame__mode-input {
    font-size0;
    positionabsolute;
    opacity0;
    width100%;
    height100%;
    left0;
    top0;
    -moz-appearancenone;
    -webkit-appearancenone;
    cursorpointer;
}

.content {
    positionrelative;
}

.content__item {
    positionabsolute;
    width100%;
    left0;
    top0;
    colorvar(--color-content);
    backgroundvar(--color-content-bg);
}

.js .content__item {
    opacity0;
    pointer-eventsnone;
}

.js .content__item--current {
    opacity1;
    pointer-eventsauto;
    top16rem;
}

.content__item-header {
    padding2rem 2rem 0;
    positionrelative;
}

.content__item-header-title {
    font-family: ivymode, sans-serif;
    font-weight600;
    font-size3rem;
    margin0;
    colorvar(--color-content-title);
}

.content__item-header-meta {
    text-indent0.25rem;
    displayblock;
    colorvar(--color-content-meta);
}

.dark-mode .content__item-header-meta {
    mix-blend-modedifference;
}

.content__item-header-meta::before {
    content'---------';
    margin0 0.5rem 0 0;
    letter-spacing-0.15rem;
}

.content__item-copy {
    padding2rem;
    font-family: linotype-didot, serif;
}

.revealer {
    positionfixed;
    width100vw;
    height100vh;
    top0;
    left0;
    transformrotate(-8deg);
    displayflex;
    align-itemscenter;
    justify-contentcenter;
    pointer-eventsnone;
}

.revealer__inner {
    background-colorvar(--color-reveal-bg);
    width200%;
    height200%;
    positionrelative;
    flexnone;
}

.grid {
    positionabsolute;
    displaygrid;
    height400px;
    width100%;
    left0;
    top0;
    grid-template-columns30% 30% 30%;
    grid-column-gap5%;
    grid-template-areas'griditem-left griditem-center griditem-right';
}

.grid--slideshow,
.grid--interaction {
    left-5%;
    width110%;
    pointer-eventsnone;
}

.grid--slideshow {
    top17rem;
    transformrotate(-8deg);
}

.grid--titles {
    align-itemscenter;
    text-aligncenter
    cursordefault;
}

.titles-wrap {
    positionabsolute;
    width100%;
    height100%;
    z-index1000;
    pointer-eventsnone;
    transformrotate(16deg);
}

.grid__item {
    displayflex;
    justify-contentcenter;
    positionrelative;
    pointer-eventsnone;
    opacity0;
    grid-area: griditem-center;
}

.grid__item--slide {
    flex-directioncolumn;
    width100%;    
}

.grid__item--title {
    font-size13vw;
    margin0;
    font-family: ivymode, sans-serif;
    font-weight600;
    colorvar(--color-title);
}

.grid__item--title span {
    displayinline-block;
}

.grid__item--center,
.grid__item--left,
.grid__item--right {
    opacity1;
    cursorpointer;
}

.grid__item--left {
    grid-area: griditem-left;
}

.grid__item--center {
    grid-area: griditem-center;
}

.grid__item--right {
    grid-area: griditem-right;
}

.grid__item--cursor {
    pointer-eventsauto;
}

.content-open .grid__item--cursor {
    displaynone;
}

.number {
    font-size2rem;
    -webkit-text-stroke1.5px var(--color-number);
    text-stroke: 1.5px var(--color-number);
    -webkit-text-fill-colortransparent;
    text-fill-color: transparent;
    colortransparent
    line-height1;
    margin0 0 0.5rem 0;
    font-weight700;
}

.img-wrap {
    width100%;
    overflowhidden;
    positionrelative;
    height100%;
}

.img-wrap--content {
    height200px;
}

.img {
    widthcalc(100% + 40px);
    height100%;
    left-20px;
    top0;
    background-sizecover;
    background-position50% 50%;
    positionabsolute;
    pointer-eventsnone;
}

.img--content {
    background-position50% 38%;
}

.caption {
    text-transformuppercase;
    letter-spacing0.1rem;
    font-size0.75rem;
    font-weight400;
    margin0.75rem 0 0 0;
    colorvar(--color-caption);
}


.caption::before {
    content'---------';
    margin0 0.5rem 0 0;
    letter-spacing-0.15rem;
}

.img-wrap,
.img--content,
.caption,
.number,
.grid__item--title,
.grid__item--title span,
.revealer__inner,
.content__item-header-title {
    will-change: transform;
}

.grid__item--cursor.grid__item--left::after,
.grid__item--cursor.grid__item--right::after,
.img-wrap--content::after {
    positionabsolute;
    leftcalc(50% - 30px);
    cursorpointer;
}

.grid__item--cursor.grid__item--left::after {
    top70%;
}

.grid__item--cursor.grid__item--right::after {
    top20%;
}

.grid__item--cursor.grid__item--left::after {
    contenturl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='61px' height='44px' viewBox='0 0 61 44' style='enable-background:new 0 0 61 44;' xml:space='preserve'%3E %3Cpath d='M.613 21.671L21.584.7l5.642 5.642-11.74 11.74H60.45v7.978H15.487l11.74 11.739-5.643 5.642L.613 22.469a.57.57 0 0 1 0-.798z'/%3E %3C/svg%3E");
}

.grid__item--cursor.grid__item--right::after {
    contenturl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='61px' height='44px' viewBox='0 0 61 44' style='enable-background:new 0 0 61 44;' xml:space='preserve'%3E %3Cpath d='M60.287 21.671L39.316.7l-5.642 5.642 11.74 11.74H.45v7.978h44.963l-11.74 11.739 5.643 5.642 20.971-20.972a.57.57 0 0 0 0-.798z'/%3E %3C/svg%3E");
}

.img-wrap--content::after {
    top0.5rem;
    right0.5rem;
    leftauto;
    transformscale(0.5);
    contenturl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='52px' height='52px' viewBox='0 0 52 52' style='enable-background:new 0 0 52 52;' xml:space='preserve'%3E %3Cpath  d='M20.921 26.67L5.791 41.75C5.485 41.743.23 36.488.224 36.18L15.32 21.073.098 5.86 5.74.22l15.19 15.24L36.161.22l5.64 5.64-15.27 15.22 15.097 15.15c-.006.307-5.262 5.562-5.569 5.568L20.921 26.67z'/%3E %3C/svg%3E");
}

@media screen and (min-width53em) {
    body {
        overflowhidden;
    }
    .frame {
        positionfixed;
        bottom0;
        right0;
        padding1rem;
        transition0.3s opacity;
    }
    .content-open + .frame {
        opacity0;
        pointer-eventsnone;
    }
    .frame__title-wrap {
        displayflex;
        align-itemscenter;
        justify-contentflex-end;
    }
    .frame__title {
        margin0;
    }
    .frame__links {
        margin0 1.5rem;
    }
    .frame__mode {
        margin0;
    }
    .frame a {
        pointer-eventsauto;
    }
    .grid {
        height100vh;
        grid-template-columnsrepeat(3calc((100% - 36vw/ 3));
        grid-column-gap18vw;
    }
    .grid--slideshow {
        top0;
    }
    .grid--interaction {
        grid-template-columnsrepeat(3calc(100% / 3));
        grid-column-gap0;
    }
    .number {
        font-size4.25vw;
    }
    .img-wrap {
        height35vw;
    }
    .img-wrap--content {
        height100%;
        grid-area1 / 2 / 2 / 3;
    }
    .content {
        top0;
        positionabsolute;
        height100vh;
        width100%;
    }
    .content__item {
        height100vh;
        displaygrid;
        align-itemscenter;
        grid-template-columns30% 40% 30%;
        grid-column-gap0;
    }
    .js .content__item {
        height100%;
    }
    .js .content__item--current {
        top0;
    }
    .img-wrap--content {
        height100%;
    }
    .content__item-header {
        justify-selfcenter;
        grid-area1 / 1 / 2 / 3;
        pointer-eventsnone;
    }
    .content__item-header-title {
        font-size8vw;
    }
    .content__item-copy {
        max-width240px;
        justify-selfend;
        text-alignright;
    }
    .grid__item--cursor.grid__item--left::after,
    .grid__item--cursor.grid__item--right::after,
    .img-wrap--content::after {
        displaynone;
    }
    .grid__item--cursor.grid__item--left {
        cursorurl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='61px' height='44px' viewBox='0 0 61 44' style='enable-background:new 0 0 61 44;' xml:space='preserve'%3E %3Cpath d='M.613 21.671L21.584.7l5.642 5.642-11.74 11.74H60.45v7.978H15.487l11.74 11.739-5.643 5.642L.613 22.469a.57.57 0 0 1 0-.798z'/%3E %3C/svg%3E"30 22sw-resize;
    }
    .grid__item--cursor.grid__item--center {
        cursorurl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='52px' height='52px' viewBox='0 0 52 52' style='enable-background:new 0 0 52 52;' xml:space='preserve'%3E %3Cpath d='M29.889 30.05l-.036 21.361c-.222.213-7.654.213-7.876 0l-.007-21.358-21.52.007v-7.978l21.518.036L21.96.571h7.978l-.037 21.56 21.388.037c.213.222.213 7.654 0 7.876l-21.401.007z'/%3E %3C/svg%3E"26 26crosshair;
    }
    .grid__item--cursor.grid__item--right {
        cursorurl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='61px' height='44px' viewBox='0 0 61 44' style='enable-background:new 0 0 61 44;' xml:space='preserve'%3E %3Cpath d='M60.287 21.671L39.316.7l-5.642 5.642 11.74 11.74H.45v7.978h44.963l-11.74 11.739 5.643 5.642 20.971-20.972a.57.57 0 0 0 0-.798z'/%3E %3C/svg%3E"30 22ne-resize;
    }
    .dark-mode .grid__item--cursor.grid__item--left {
        cursorurl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='61px' height='44px' viewBox='0 0 61 44' style='enable-background:new 0 0 61 44;' xml:space='preserve'%3E %3Cpath fill='%23bb3a3a' d='M.613 21.671L21.584.7l5.642 5.642-11.74 11.74H60.45v7.978H15.487l11.74 11.739-5.643 5.642L.613 22.469a.57.57 0 0 1 0-.798z'/%3E %3C/svg%3E"30 22sw-resize;
    }
    .dark-mode .grid__item--cursor.grid__item--center {
        cursorurl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='52px' height='52px' viewBox='0 0 52 52' style='enable-background:new 0 0 52 52;' xml:space='preserve'%3E %3Cpath fill='%23bb3a3a' d='M29.889 30.05l-.036 21.361c-.222.213-7.654.213-7.876 0l-.007-21.358-21.52.007v-7.978l21.518.036L21.96.571h7.978l-.037 21.56 21.388.037c.213.222.213 7.654 0 7.876l-21.401.007z'/%3E %3C/svg%3E"26 26crosshair;
    }
    .dark-mode .grid__item--cursor.grid__item--right {
        cursorurl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='61px' height='44px' viewBox='0 0 61 44' style='enable-background:new 0 0 61 44;' xml:space='preserve'%3E %3Cpath fill='%23bb3a3a' d='M60.287 21.671L39.316.7l-5.642 5.642 11.74 11.74H.45v7.978h44.963l-11.74 11.739 5.643 5.642 20.971-20.972a.57.57 0 0 0 0-.798z'/%3E %3C/svg%3E"30 22ne-resize;
    }
    .img-wrap--content {
        cursorurl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='52px' height='52px' viewBox='0 0 52 52' style='enable-background:new 0 0 52 52;' xml:space='preserve'%3E %3Cpath  d='M20.921 26.67L5.791 41.75C5.485 41.743.23 36.488.224 36.18L15.32 21.073.098 5.86 5.74.22l15.19 15.24L36.161.22l5.64 5.64-15.27 15.22 15.097 15.15c-.006.307-5.262 5.562-5.569 5.568L20.921 26.67z'/%3E %3C/svg%3E"21 21pointer;
    }
    .dark-mode .img-wrap--content {
        cursorurl("data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='52px' height='52px' viewBox='0 0 52 52' style='enable-background:new 0 0 52 52;' xml:space='preserve'%3E %3Cpath fill='%23bb3a3a' d='M20.921 26.67L5.791 41.75C5.485 41.743.23 36.488.224 36.18L15.32 21.073.098 5.86 5.74.22l15.19 15.24L36.161.22l5.64 5.64-15.27 15.22 15.097 15.15c-.006.307-5.262 5.562-5.569 5.568L20.921 26.67z'/%3E %3C/svg%3E"21 21pointer;
    }
}





Javascript (.js file) SOURCE_CODE:-

{
    const MathUtils = {
        lineEq: (y2y1x2x1currentVal=> {
            // y = mx + b 
            var m = (y2 - y1) / (x2 - x1), b = y1 - m * x1;
            return m * currentVal + b;
        },
        lerp: (abn=>  (1 - n) * a + n * b,
        distance: (x1x2y1y2=> {
            var a = x1 - x2;
            var b = y1 - y2;
            return Math.hypot(a,b);
        },
        randomNumber: (min,max=> Math.floor(Math.random()*(max-min+1)+min)
    };

    let winsize;
    const calcWinsize = () => winsize = {width: window.innerWidthheight: window.innerHeight};
    calcWinsize();
    window.addEventListener('resize'calcWinsize);

    const getMousePos = (ev=> {
        let posx = 0;
        let posy = 0;
        if (!evev = window.event;
        if (ev.pageX || ev.pageY) {
            posx = ev.pageX;
            posy = ev.pageY;
        }
        else if (ev.clientX || ev.clientY)  {
            posx = ev.clientX + body.scrollLeft + docEl.scrollLeft;
            posy = ev.clientY + body.scrollTop + docEl.scrollTop;
        }
        return {x: posxy: posy};
    }



    let mousePos = {x: winsize.width/2y: winsize.height/2};
    window.addEventListener('mousemove'ev => mousePos = getMousePos(ev));

    class Slide {
        constructor(eltitle) {
            this.DOM = {el: el};
            this.DOM.title = title;
            charming(this.DOM.title);
            this.DOM.titleLetters = [...this.DOM.title.querySelectorAll('span')];
            this.DOM.titleLetters.sort(() => Math.round(Math.random())-0.5);
            this.DOM.number = this.DOM.el.querySelector('.number');
            this.DOM.subtitle = this.DOM.el.querySelector('.caption');
            this.DOM.imgWrap = this.DOM.el.querySelector('.img-wrap');
            this.DOM.img = this.DOM.imgWrap.querySelector('.img');
        }
        
        move(directionval) {
            return new Promise((resolvereject=> {
                const tx = direction === 'left' ? '+=' + val*-1 : '+=' + val;
                const duration = 1.2;
                
                new TimelineMax({onComplete: resolve})
                .to(this.DOM.imgWrapduration, {
                    x: tx,
                    ease: Quart.easeInOut
                }, 0)
                .to(this.DOM.imgWrapduration*.5, {
                    scaleX: 1.3,
                    ease: Quart.easeIn
                }, 0)
                .to(this.DOM.imgWrapduration*.5, {
                    scaleX: 1,
                    ease: Quart.easeOut
                }, duration*.5
                .to(this.DOM.numberduration*.95, {
                    x: tx,
                    ease: Quint.easeInOut
                }, 0)
                .to(this.DOM.subtitleduration*1.1, {
                    x: tx,
                    ease: Quart.easeInOut
                }, 0)
                .to(this.DOM.titleduration*1.05, {
                    x: tx,
                    ease: Quart.easeInOut
                }, 0);
            });
        }
        setCenter() {
            this.isCenter = true;
            this.DOM.el.classList.add('grid__item--center');
            this.DOM.title.classList.add('grid__item--center');
            TweenMax.set([this.DOM.elthis.DOM.title], {opacity: 1});
        }
        setRight() {
            this.isRight = this.isCenter = false;
            this.isLeft = true;
            this.DOM.el.classList.add('grid__item--right');
            this.DOM.title.classList.add('grid__item--right');
            TweenMax.set([this.DOM.elthis.DOM.title], {opacity: 1});
        }
        setLeft() {
            this.isLeft = this.isCenter = false;
            this.isRight = true;
            this.DOM.el.classList.add('grid__item--left');
            this.DOM.title.classList.add('grid__item--left');
            TweenMax.set([this.DOM.elthis.DOM.title], {opacity: 1});
        }
        reset() {
            TweenMax.set([this.DOM.elthis.DOM.imgWrapthis.DOM.numberthis.DOM.subtitlethis.DOM.title], {transform: 'none'});
            TweenMax.set([this.DOM.elthis.DOM.title], {opacity: 0});
            this.DOM.title.classList = 'grid__item grid__item--title';
            this.DOM.el.classList = 'grid__item grid__item--slide';
        }
        animateElementsOut(contentItem) {
            return new Promise((resolvereject=> {
                const time = MathUtils.randomNumber(0,100)/500;
                this.elemsTimeline = new TimelineMax({onComplete: resolve})
                .staggerTo(this.DOM.titleLetters1, {
                    y: MathUtils.randomNumber(300,600),
                    opacity: 0,
                    ease: Quart.easeInOut
                }, 0.04time)
                .staggerTo(this.DOM.titleLetters0.5, {
                    scaleY: 2.2,
                    ease: Quart.easeIn
                }, 0.04time)
                .staggerTo(this.DOM.titleLetters0.5, {
                    scaleY: 1,
                    ease: Quart.easeOut
                }, 0.04time + 0.5)
                .to(this.DOM.number1, {
                    y: -500,
                    opacity: 0,
                    ease: Quart.easeInOut
                }, time+0.3)
                .to(this.DOM.imgWrap0.8, {
                    y: -500,
                    opacity: 0,
                    ease: Quart.easeInOut
                }, time+0.4)
                .to(this.DOM.imgWrap.4, {
                    scaleX: 0.95,
                    scaleY: 1.4,
                    ease: Quart.easeIn
                }, time+0.4)
                .to(this.DOM.imgWrap.4, {
                    scaleX: 1,
                    scaleY: 1,
                    ease: Quart.easeOut
                }, time+0.4 + 0.4)
                .to(this.DOM.subtitle1, {
                    y: -500,
                    opacity: 0,
                    ease: Quart.easeInOut
                }, time+0.5);

                if ( this.isCenter ) {
                    const contentItemTitle = contentItem.querySelector('.content__item-header-title');
                    const contentItemImg = contentItem.querySelector('.img--content');
                    this.elemsTimeline.to(contentItemTitle0.8, {
                        ease: Expo.easeOut,
                        startAt: {y: '100%'opacity: 0rotation: -16},
                        y: '0%',
                        rotation: 0,
                        opacity: 1
                    }, time+1.3)
                    .set(contentItemImg, {scale: 1.2}, 0)
                    .to(contentItemImg0.8, {
                        ease: Expo.easeOut,
                        scale: 1
                    }, time+1.3)
                    .to(revealer.DOM.el1, {
                        ease: Quint.easeOut,
                        y: '-100%'
                    }, time+1.2);
                }
            });
        }
        animateElementsIn(contentItem) {
            return new Promise((resolvereject=> {
                const time = MathUtils.randomNumber(0,50)/500;
                this.elemsTimeline = new TimelineMax({onComplete: resolve});
                
                if ( this.isCenter ) {
                    const contentItemTitle = contentItem.querySelector('.content__item-header-title');
                    const contentItemImg = contentItem.querySelector('.img--content');
                    this.elemsTimeline.to(contentItemTitle1, {
                        ease: Quint.easeOut,
                        y: '50%',
                        opacity: 0
                    }, 0)
                    .to(contentItemImg1, {
                        ease: Quint.easeOut,
                        scale: 1.2
                    }, 0)
                    .to(revealer.DOM.el1, {
                        ease: Quint.easeOut,
                        y: '0%'
                    }, 0);
                }
                this.elemsTimeline.to(this.DOM.subtitle0.8, {
                    y: 0,
                    opacity: 1,
                    ease: Quart.easeOut
                }, time)
                .to(this.DOM.imgWrap0.8, {
                    y: 0,
                    opacity: 1,
                    scaleX: 1,
                    scaleY: 1,
                    ease: Quart.easeOut
                }, time+0.1)
                .to(this.DOM.number0.8, {
                    y: 0,
                    opacity: 1,
                    ease: Quart.easeOut
                }, time+0.2)
                .staggerTo(this.DOM.titleLetters0.8, {
                    y: 0,
                    opacity: 1,
                    scaleX: 1,
                    scaleY: 1,
                    ease: Quart.easeOut
                }, 0.03time+0.1)
            });
        }
    }

    class Slideshow {
        constructor(el) {
            this.DOM = {el: el};
            // The titles
            this.DOM.titlesWrap = this.DOM.el.querySelector('.titles-wrap');
            this.DOM.titlesInner = this.DOM.titlesWrap.querySelector('.grid--titles');
            this.DOM.titles = [...this.DOM.titlesInner.querySelectorAll('.grid__item--title')];
            // The slides instances
            this.slides = [];
            [...this.DOM.el.querySelectorAll('.grid__item--slide')].forEach((slidepos=> this.slides.push(new Slide(slidethis.DOM.titles[pos])));
            // Total number of slides
            this.slidesTotal = this.slides.length;
            if ( this.slidesTotal < 4 ) return;
            // Center slide's position
            this.center = 0;

            // Content Items
            this.DOM.contentItems = [...document.querySelectorAll('.content__item')];

            // Areas (left, center, right) where to attach the navigation events.
            this.DOM.interaction = {
                left: document.querySelector('.grid__item--left'),
                center: document.querySelector('.grid__item--center'),
                right: document.querySelector('.grid__item--right')
            };
            
            this.setVisibleSlides();
            this.calculateGap();
            this.initEvents();

            let mouseMoveVals = {translation: 0rotation: -8};
            const render = () => {
                //if ( !this.isAnimating ) {
                    mouseMoveVals.translation = MathUtils.lerp(mouseMoveVals.translationMathUtils.lineEq(-1515winsize.width0mousePos.x), 0.03);
                    //mouseMoveVals.rotation = MathUtils.lerp(mouseMoveVals.rotation, MathUtils.lineEq(-8.5, -7.5, winsize.width, 0, mousePos.x), 0.03);
                    for (let i = 0i <= this.slidesTotal - 1; ++i) {
                        TweenMax.set(this.slides[i].DOM.img, {x: mouseMoveVals.translation});
                        TweenMax.set(this.DOM.titlesInner, {x: -4*mouseMoveVals.translation});
                        //TweenMax.set(this.DOM.el, {rotation: mouseMoveVals.rotation});
                        //TweenMax.set(this.DOM.titlesWrap, {rotation: -2*mouseMoveVals.rotation});
                    }
                //}
                requestAnimationFrame(render);
            }
            requestAnimationFrame(render);
        }
        setVisibleSlides() {
            this.centerSlide = this.slides[this.center];
            this.rightSlide = this.slides[this.center+1 <= this.slidesTotal-1 ? this.center+1 : 0];
            this.leftSlide = this.slides[this.center-1 >= 0 ? this.center-1 : this.slidesTotal-1];
            this.centerSlide.setCenter();
            this.rightSlide.setRight();
            this.leftSlide.setLeft(); 
        }
        // Distance between 2 slides 
        // The amount to translate the elements that move when we navigate the slideshow
        calculateGap() {
            const s1 = this.slides[0].DOM.el.getBoundingClientRect();
            const s2 = this.slides[1].DOM.el.getBoundingClientRect();
            this.gap = MathUtils.distance(s1.left + s1.width/2s2.left + s2.width/2s1.top + s1.height/2s2.top + s2.height/2);
        }
        // Initialize events
        initEvents() {
            this.clickRightFn = () => this.navigate('right');
            this.DOM.interaction.right.addEventListener('click'this.clickRightFn);
            
            this.clickLeftFn = () => this.navigate('left');
            this.DOM.interaction.left.addEventListener('click'this.clickLeftFn);
            
            this.clickCenterFn = () => this.openSlide();
            this.DOM.interaction.center.addEventListener('click'this.clickCenterFn);

            this.mouseenterCenterFn = () => {
                if ( this.isAnimating ) {
                    return;
                }
                new TimelineMax()
                .to(this.centerSlide.DOM.imgWrap0.7, {
                    ease: Expo.easeOut,
                    scale: 1.02
                })
                .to(this.centerSlide.DOM.img1.7, {
                    ease: Expo.easeOut,
                    scale: 1.05
                }, 0);
            };
            this.DOM.interaction.center.addEventListener('mouseenter'this.mouseenterCenterFn);

            this.mouseleaveCenterFn = () => {
                if ( this.isAnimating ) {
                    return;
                }
                new TimelineMax().to(this.centerSlide.DOM.imgWrap0.7, {
                    ease: Expo.easeOut,
                    scale: 1
                })
                .to(this.centerSlide.DOM.img0.7, {
                    ease: Expo.easeOut,
                    scale: 1
                }, 0);
            };
            this.DOM.interaction.center.addEventListener('mouseleave'this.mouseleaveCenterFn);

            this.resizeFn = () => this.calculateGap();
            window.addEventListener('resize'this.resizeFn);

            this.DOM.contentItems.forEach(item => {
                item.querySelector('.img-wrap--content').addEventListener('click', () => this.closeSlide());
            });
        }
        navigate(direction) {
            if ( this.isAnimating ) {
                return false;
            }
            this.isAnimating = true;
            
            const upcomingPos = direction === 'right' ? 
                    this.center < this.slidesTotal-2 ? this.center+2 : Math.abs(this.slidesTotal-2-this.center):
                    this.center >= 2 ? this.center-2 : Math.abs(this.slidesTotal-2+this.center);

            // Update current.
            this.center = direction === 'right' ? 
                    this.center < this.slidesTotal-1 ? this.center+1 : 0 :
                    this.center > 0 ? this.center-1 : this.slidesTotal-1;

            this.upcomingSlide = this.slides[upcomingPos];
            this.upcomingTitle = this.upcomingSlide.DOM.title;
            // Position upcomingSlide / upcomingTitle
            TweenMax.set(this.upcomingSlide.DOM.el, {x: direction === 'right' ? this.gap*2 : -1*this.gap*2opacity: 1});
            TweenMax.set(this.upcomingTitle, {x: direction === 'right' ? this.gap*2 : -1*this.gap*2opacity: 1});
            
            const movingSlides = [this.upcomingSlidethis.centerSlidethis.rightSlidethis.leftSlide];
            let promises = [];
            movingSlides.forEach(slide => promises.push(slide.move(direction === 'right' ? 'left' : 'right'this.gap)));
            Promise.all(promises).then(() => {
                // After all is moved, update the classes of the 3 visible slides and reset styles
                movingSlides.forEach(slide => slide.reset());
                // Set it again
                this.setVisibleSlides();
                this.isAnimating = false;
            });
        }
        openSlide() {
            this.toggleSlide('open');
        }
        closeSlide() {
            this.toggleSlide('close');
        }
        toggleSlide(action) {
            if ( this.isAnimating ) {
                return;
            }
            this.isAnimating = true;

            const contentItem = this.DOM.contentItems[this.center];
            // Cursor styles related class
            this.DOM.el.classList[action === 'open' ? 'add' : 'remove']('content-open');

            const movingSlides = [this.centerSlidethis.rightSlidethis.leftSlide];
            let promises = [];
            movingSlides.forEach(slide => promises.push(slide[action === 'open' ? 'animateElementsOut' : 'animateElementsIn'](contentItem)));
            
            if ( action === 'open' ) {
                contentItem.classList.add('content__item--current');
            }
            Promise.all(promises).then(() => {
                if ( action === 'close' ) {
                    contentItem.classList.remove('content__item--current');
                }
                this.isAnimating = false;
            });
        }
    }

    class Revealer {
        constructor(el) {
            this.DOM = {el: el};
            this.DOM.el.style.width = `calc(100vw * ${Math.cos(8 * Math.PI/180)} + 100vh * ${Math.sin(8 * Math.PI/180)})`;
            this.DOM.el.style.height = `calc(100vw * ${Math.sin(8 * Math.PI/180)} + 100vh * ${Math.cos(8 * Math.PI/180)})`;
        }
    }

    // Revealer element
    const revealer = new Revealer(document.querySelector('.revealer__inner'));
    // Initialize the slideshow
    new Slideshow(document.querySelector('.grid--slideshow'));

    // Preload all the images in the page
    imagesLoaded(document.querySelectorAll('.img'), {background: true}, () => document.body.classList.remove('loading'));
    
    [...document.querySelectorAll('.frame__mode input[type="radio"]')].forEach(radio => radio.addEventListener('click', () => {
        document.body.classList[radio.parentNode.classList.contains('frame__mode-item--dark') ? 'add' : 'remove']('dark-mode');
    }));
}




web design video My YOUTUBE channel








































Comments

Popular posts from this blog

Create A Pizza Website Using HTML And CSS and GSAP| Page transition animation by gsap. Artspider

https://cdnjs.cloudflare.com/ajax/libs/gsap/3.5.1/gsap.min.js SOURCE CODE HTML  SOURCE_CODE:- index .html 👇 <! DOCTYPE   html > < html > < head >      < meta   charset = 'utf-8' >      < meta   http-equiv = 'X-UA-Compatible'   content = 'IE=edge' >      < title > home page transion </ title >      < meta   name = 'viewport'   content = 'width=device-width, initial-scale=1' >      < link   rel = 'stylesheet'   type = 'text/css'   media = 'screen'   href = 'main.css' >      </ head > < body   >          < div   class = "cover" >          < img   src = "img/logo.png"   alt = ""   class = "logo" >      ...

How To Make A Website Using HTML CSS & Bootstrap | Personal Portfolio Website Design Tutorial

How To Make A Website Using HTML CSS & Bootstrap | Personal Portfolio Website Design Tutorial SOURCE CODE HTML  SOURCE_CODE:- index .html 👇 <!DOCTYPE html> <html> <head>     <meta charset='utf-8'>     <meta http-equiv='X-UA-Compatible' content='IE=edge'>     <title>Page Title</title>     <meta name='viewport' content='width=device-width, initial-scale=1'>     <!-- Google Fonts -->   <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">   <!-- Vendor CSS Files -->   <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">   <link href="assets/vendor/icofont/icofont.min.css" rel="stylesheet">   <link href="assets/v...

How to create Page transition animation by Greensock (gsap)?

 Create Page transition animation by Greensock (gsap) https://cdnjs.cloudflare.com/ajax/libs/gsap/3.5.1/gsap.min.js SOURCE CODE HTML  SOURCE_CODE:- index .html 👇 <! DOCTYPE   html > < html > < head >      < meta   charset = 'utf-8' >      < meta   http-equiv = 'X-UA-Compatible'   content = 'IE=edge' >      < title >  index Page  </ title >      < meta   name = 'viewport'   content = 'width=device-width, initial-scale=1' >      < link   rel = 'stylesheet'   type = 'text/css'   media = 'screen'   href = 'main.css' >      </ head > < body >      < div   class = "header" >          < a   href = "#" >         ...