Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="stage" ng-app="kodaline" ng-controller="TimelineController" >

        <!-- Tile Grid View -->
        <div id="status" class="status"></div>
        <div id="header"></div>

        <div class="tile1" ng-click="showDetails(0)" ></div>
        <div class="tile2" ng-click="showDetails(1)" ></div>
        <div class="tile3" ng-click="showDetails(2)" ></div>
        <div class="tile4" ng-click="showDetails(3)" ></div>

        <div id="other"></div>
        <div id="footer"></div>

        <!-- Tile Grid Mask -->
        <div id="mask" class="hidden"></div>

        <!-- Tile Details View -->
        <div id="green_status" class="hidden"></div>
        <div id="details" class="hidden">
            <img src="" class="scaled">
            <div id="title" >
                <div class="content"></div>
            </div>
            <div id="info" >
                <div class="content"></div>
            </div>
            <div id="pause">
                <img src="https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/pause.png" class="pause">
            </div>
        </div>

        <div id="timeline-slider" class="timeline-slider-container hidden" ng-controller="TimelineSliderController">
            <input type="range"
                   ng-model="slider.position"
                   ng-mousedown="isDragging(true)"
                   ng-mouseup="isDragging(false)"
                   step="{{slider.step}}"
                   min="0" max="{{slider.totalDuration}}"
                   class="repeat-slider">
        </div>

    </div>
              
            
!

CSS

              
                body {
    margin: 0;
    padding: 0;
    background-color: #3e3e3e;
    padding: 10px;
}

#stage {
    position: relative;
    height: 634px;
    width: 323px;
    z-index: 0;
    overflow: hidden;
    text-overflow: clip;
    background-color: rgb(255, 255, 255,0);
    background-size: 100% 100%;
    opacity:0;
}

#stage > div {
    position: absolute;
    margin: 0px;
    right: auto;
    bottom: auto;
    left: 0px;
    background-color: rgba(0, 0, 0, 0);
    background-size: 100% 100%;
    background-position: 0px 0px;
    background-repeat: no-repeat;
}

.hidden {
    display: none;
}

.scaled {
    width: 100%
}

#stage > div#status {
    top: 0px;
    width: 323px;
    height: 21px;
    background-image: url(https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/status.png);
}

#stage > div#green_status {
    top: 21px;
    width: 323px;
    height: 18px;
    background-image: url(https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/zoomed_header.png);
}

#stage > div#header {
    top: 21px;
    width: 323px;
    height: 53px;
    background-image: url(https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/header.png);
}

#stage > div#tile1, #stage > div.tile1 {
    top: 74px;
    width: 162px;
    height: 164px;
    background-image: url(https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/thumb_kodaline_v3.png);
    cursor: zoom-in;
}

#stage > div#tile2, #stage > div.tile2 {
    left: 162px;
    top: 74px;
    width: 161px;
    height: 164px;
    background-image: url(https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/thumb_moby_v3.png);
    cursor: zoom-in;
}

#stage > div#tile3, #stage > div.tile3 {
    top: 238px;
    width: 162px;
    height: 223px;
    background-image: url(https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/thumb_supermodel.png);
    cursor: zoom-in;
}

#stage > div#tile4, #stage > div.tile4 {
    left: 162px;
    top: 238px;
    width: 161px;
    height: 223px;
    background-image: url(https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/thumb_goulding.png);
    cursor: zoom-in;
}


#stage > div#details {
    top: 75px;
    width: 162px;
    height: 162px;
    overflow: hidden;
    z-index: 100;
    cursor: zoom-out;
}

#stage div#title {
    margin-top: -4px;
    position: relative;
    width: 323px;
    height: 0px;
    /*height: 131px;*/
    background: #3c6373;
}

#stage div#title > .content {
    opacity: 0;
    width: 323px;
    height: 131px;
}

#stage div#info {
    position: relative;
    width: 323px;
    height: 0px;
    /*height: 56px;*/
    background: white;
}

#stage div#info > .content {
    opacity: 0;
    width: 323px;
    height: 56px;
}


#stage > div#other {
    top: 461px;
    width: 323px;
    height: 71px;
    background-image: url(https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/otherTiles.png);
}

#stage > div#footer {
    top: 532px;
    width: 323px;
    height: 42px;
    background-image: url(https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/footer.png);
}

#stage > div#mask {
    z-index: 0;
    background-color: rgba(0, 0, 0, 1);
    opacity: 0.0;
    top: 75px;
    width: 324px;
    height: 458px;
}

#pause {
    position: absolute;

    top: 305px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #67CABC;
    -webkit-box-shadow: 2px 4px 3px 0px rgba(20, 20, 20, 0.7);
    -moz-box-shadow: 2px 4px 3px 0px rgba(20, 20, 20, 0.7);
    box-shadow: 2px 4px 3px 0px rgba(20, 20, 20, 0.7);

    -webkit-transform: scale(0.4);
    -moz-transform: scale(0.4);
    transform: scale(0.4);
    opacity: 0;
    overflow: hidden;
}

.pause {
    margin-left: 4px;
    margin-top: 5px;
}

div#title > img, div#info > img {
    opacity: 0;
}

#stage .timeline-slider-container {
    position: absolute;
    top: 590px;
    left: 40px;
    background: #ffffff;
    border-radius: 3px;
    width: 70%;
    height: 10px;
    padding: 10px;
}

#stage input[type=range] {
    display: block;
    background-color: #383838;
    width: 100%;
    height: 5px;
    border-radius: 5px;
    vertical-align: middle;
    margin-top: 2px;
}

#stage .repeat-slider {
    border: 0;
    border-radius: 3px;
    margin: auto;
    height: 50px;
    width: 90%;
}

              
            
!

JS

              
                /**
     * Purpose:
     *
     * Use GSAP `TimelineLite` to demonstrate use of animation timelines to build complex transitions.
     * Explore the API usages & complexities of functionality required to create the desired effects and UX.
     *
     * Some other considerations:
     *
     * - Load images in background so zoom works quickly
     * - Use promises to delay transitions until the images are ready
     * - Dynamically modify timescale so unzoom is faster
     * - Use of global keypress to unzoom/reverse the timeline
     * - Use tile data model to define dynamic zoom from/to information
     * - Plugin use of Timeline Slider controls; independent of TimelineController
     *   - Sync Slider to transition timeline
     *   - Use slider to manually sequence through transition frames
     * - Support to drag on image to manually sequence through transitions
     *
     *  //cdnjs.cloudflare.com/ajax/libs/gsap/1.14.2/TweenMax.min.js
     *  //cdnjs.cloudflare.com/ajax/libs/q.js/1.1.2/q.js
     *  //ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.js
     *
     */
    angular.module("kodaline",['ng'])
           .factory( "tiles", TileDataModel )
           .controller("TimelineController",       TimelineController )
           .controller("TimelineSliderController", TimelineSliderController );

    /**
     * TimelineController constructor
     * @constructor
     */
    function TimelineController( $scope, tiles, $q ) {
      
        $scope.timeline = null;
        $scope.showDetails = showDetails;
        $scope.hideDetails = angular.noop;


        scaleStage();
        $('body').keydown( autoClose );
        $('#mask').mousedown( autoClose );

        loadImages()
            .then( getTransitions )
            .then( function(transitions){
                // set default or initial timeline
                showDetails(0);
    
            });

        // **************************************************
        // Build Animation Timelines
        // **************************************************

        /**
         * Getter/Setter for currentl Timeline instance
         * which is published on the scope for access by
         * the child TimelineSliderController
         *
         * @param tl
         */
        function timeline(tl) {
            if (tl === undefined ) {
                return $scope.timeline;
            }
            else if(!$scope.$$phase) {
                $scope.$apply(function(){
                    $scope.timeline = tl;
                });
            } else {
                $scope.timeline = tl;
            }
          
          return $scope.timeline;
        }
        /**
         * Open Details view upon tile clicks
         * Run custom `Show Details` view transitions
         *
         */
        function showDetails(tileIndex) {
            loadTileImages(tiles[tileIndex]).then(function()
            {
                getTransitions(tileIndex).then( function(transitions)
                {
                    var details = document.getElementById("details");

                    // Only use the `zoom` transition for now...

                    timeline(transitions.enter);

                    // After reveal full details, the next `click` will 
                    // shrink to hide the details... back to the thumbnail view.
          
                    $scope.hideDetails = details.onclick = function() {
                        // Shrink is faster than the reveal effect
                        timeline().timeScale(1.8).reverse();
                    };

                    
                    timeline().timeScale(1.4).restart();
                });
            });
        }


        /**
         * Get a promise for the enter & leave transitions...
         * which will be resolved when the transitions are ready!
         *
         * @param tile
         * @returns {*}
         */
        function getTransitions(index) {

            var options = tiles[ index || 0 ];
            if ( !options.transitions ) {
                // If not cached, build it.
                options.transitions = buildTransitions(options);
            }

            return $q.when(options.transitions);
        }


        /**
         * Build the enter and leave transitions for the details
         *
         * @param start
         * @param fullWidth
         * @returns {{enter: TimelineLite, leave: TimelineLite}}
         */
        function buildTransitions(options) {
            var mask = document.getElementById("mask"),
                details = document.getElementById("details"),
                green = document.getElementById("green_status"),
                pause = document.getElementById("pause"),
                title = document.getElementById("title"),
                info = document.getElementById("info"),
                title_cnt = title.children[0],
                info_cnt  = info.children[0];

            var zoom = new TimelineLite({paused:true,   data:{id:'zoom'} }),
                unzoom = new TimelineLite({paused:true, data:{id:'unzoom'} });

            var from = options.from,
                to   = options.to;

            // Do zoom to show Kodaline details...

            zoom.timeScale(1)
                .set(mask,             { zIndex:90, className:""})
                .set(details,          angular.extend( options.from,{className:'',opacity:0} ) )
                .to( details,  0.3,    { opacity:1} )
                .to( details,  0.3,    { left:0, height:to.height, width:329 } )
                .addLabel("fullWidth")
                .to( mask,        0.5, { opacity:0.80 },        "fullWidth-=0.3" )
                .to( details,     0.3, { top:18, height:512 },  "fullWidth-=0.05" )
                .addLabel("slideIn")
                .set(green,            { zIndex:92, opacity:1.0, top:21, className:"" })
                .to( green,       0.2, { top:0 },                "slideIn" )
                .to( title,       0.6, { height:131 },           "fullWidth")
                .to( info,        0.5, { height:56 },            "fullWidth+=0.2")
                .to( title_cnt,   0.8, { opacity:1 },            "fullWidth+=0.3")
                .to( pause,       0.4, { opacity:1, scale:1.0 }, "fullWidth+=0.4")
                .to( info_cnt,    0.4, { opacity:1 },            "fullWidth+=0.6");


            return { enter : zoom, leave : unzoom };
        }

        // ************************************************************
        // Image Features
        // ************************************************************

        /**
         * Load all the full-size images in the background...
         */
        function loadImages() {
            try {

                // Sequentially load the tiles (not parallel)
                // NOTE: we are using the same `img src` to do the loading

                return tiles.reduce(function(promise, tile ){
                    return promise.then(function(){
                        return loadTileImages(tile).then(function(){
                            return 0; // first tile index
                        });
                    });

                }, Q.when(true))

            } catch( e ) { ; }
        }

        /**
         * Preload background and foreground images before transition start
         * Only load() 1x using the `imageLoaded` flag
         */
        function loadTileImages(source) {

            var deferred = Q.defer();
            // Update the background image for the `title` div

            $("#stage div#title > .content").css("background-image", "url(" + source.titleSrc + ")");
            $("#stage div#info  > .content").css("background-image", "url(" + source.infoSrc + ")");

            // Use a promise to start the transition ONCE the full album image has
            // already loaded and the img `src` attribute has been updated...

            if ( !source.imageLoaded ) {
                $("#details > img")
                    .load(function(){
                        // Manually track load status
                        source.imageLoaded = true;
                        deferred.resolve(source.transitions);
                    })
                    .attr("src", source.albumSrc);
            } else {
                $("#details > img").attr("src", source.albumSrc);
                deferred.resolve(source.transitions);
            }

            return deferred.promise;
        }

        // ************************************************************
        // Other Features - autoClose and Scaling
        // ************************************************************


        /**
         * Auto-close details view upon ESCAPE keydowns
         */
        function autoClose(e) {
            if ((e.keyCode == 27) || (e.type == "mousedown")) {
                ($scope.hideDetails || angular.noop)();
                e.preventDefault();
            }
        }


        /**
         * Startup viewport scaling for UX; this will increase
         * the stage size to fill the window area with
         * PROPORTIONAL_FIT_INSIDE
         */
        function scaleStage() {
            var showSlider = !isMobile();
            var win = {
                    width : $(window).width()-20,
                    height: $(window).height()-(showSlider ? 160 : 20)
                },
                stage = {
                    width : 323,
                    height: 574
                },
                scaling = Math.min(
                    win.height/stage.height,
                    win.width/stage.width
                );

            if ( showSlider ) $("#timeline-slider").removeClass("hidden");

            // Scale and FadeIn entire stage for better UX

            new TimelineLite()
                .set('#stage', {scale:scaling, transformOrigin:"0 0 0" })
                .to("#stage", 0.5, {opacity:1});

            /**
             * Check if we are rendering on a mobile device... Needed so we do not show
             * the `timeline slider` control
             */
            function isMobile() {
                return navigator.userAgent.match(/Android|BlackBerry|iPhone|iPad|iPod}/i);
            }
        }

    }

    /**
     * TimelineSliderController constructor
     * @constructor
     */
    function TimelineSliderController($scope) {
        var manualDrag = false,
            slider = {
                position      : 0.0,
                totalDuration : 0.0,
                step          : 0.05
            },
            currentTimeline = function() { return $scope.timeline; },
            currentPosition = function() { return slider.position; },
            /**
             *  Make sure that the specified timeline always provides
             *  progress updates... so we can sync the slider controls.
             */
            changeUpdateListeners = function(current, previous) {

                // Remove listener from previous timeline
                // Add onUpdate listener to current timeline (to track progress)

                if ( previous ) previous.eventCallback("onUpdate", null);
                if ( current )  current.eventCallback("onUpdate", onTimeLineUpdate, ["{self}"]);

                sliderMax( current ? current.totalDuration() : 0);
            },
            /**
             * Update timeline position to match with current slider thumb position
             * @param position
             */
            changeTimelinePosition = function(position) {
                if ( manualDrag && $scope.timeline ) {
                    $scope.timeline.time( position, true );
                }
            };


        $scope.slider = slider;
        $scope.isDragging = function(active) {
            manualDrag = active;
            if ( active == true ) {
                $scope.timeline.pause();
            } else if ( $scope.timeline.position < 0.01 ) {
              $scope.hideDetails();  
            }
        };

        $scope.$watch( currentTimeline, changeUpdateListeners  );
        $scope.$watch( currentPosition, changeTimelinePosition );


        // **************************************************
        // Timeline Slider Methods and Data Binding Features
        // **************************************************

        /**
         * Update Slider thumb position to match with current Timeline position
         * @param timeline
         */
        function onTimeLineUpdate(timeline) {
            if ( manualDrag ) return;

            var position = timeline.totalTime();

            if (timeline.data.id == "unzoom") {
                // Since the unzoom is NOT a zoom.reverse()
                // We simulate the progress position decreasing...
                position = $scope.slider.totalDuration - position;
            }

            sliderPosition( position );
        }

        /**
         * Getter/Setter for the slider max range value
         */
        function sliderMax(value) {
            if ( value === undefined ) {
                return $scope.slider.totalDuration;
            }
            else if(!$scope.$$phase) {
                $scope.$apply(function(){
                    $scope.slider.totalDuration = value;
                });
            } else {
                $scope.slider.totalDuration = value;
            }
        }

        /**
         * Getter/Setter for the slider thumb position
         * @param value
         * @returns {number}
         */
        function sliderPosition(value) {
            if ( value === undefined ) {
                return $scope.slider.position;
            }
            else  if(!$scope.$$phase) {
                $scope.$apply(function(){
                    $scope.slider.position = value;
                });
            } else {
                $scope.slider.position = value;
            }
        }
    }

    /**
     * Tile DataModel factory for model data used in Tile animations
     * @constructor
     */
    function TileDataModel() {
        return [
            {
                from: {
                    left:0,
                    top: 75,
                    width: 160,
                    height: 164
                },
                to : {
                    height : 216
                },
                thumbSrc: "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/thumb_kodaline_v3.png",
                albumSrc: "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/album_kodaline.png",
                titleSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/title_kodaline.png",
                infoSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/info_kodaline.png"
            },
            {
                from: {
                    left:165,
                    top: 75,
                    width: 160,
                    height: 166
                },
                to : {
                    height : 216
                },
                thumbSrc: "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/thumb_moby_v3.png",
                albumSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/album_moby_v2.png",
                titleSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/title_moby.png",
                infoSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/info_moby.png"
            },
            {
                from: {
                    left:0,
                    top: 240,
                    width: 159,
                    height: 221
                },
                to : {
                    height : 229
                },
                thumbSrc: "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/thumb_supermodel.png",
                albumSrc: "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/album_supermodel.png",
                titleSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/title_supermodel.png",
                infoSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/info_supermodel.png"

            },
            {
                from: {
                    left: 164,
                    top: 240,
                    width: 160,
                    height: 223
                },
                to : {
                    height : 229
                },
                thumbSrc: "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/thumb_goulding.png",
                albumSrc: "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/album_goulding.png",
                titleSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/title_goulding.png",
                infoSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/info_goulding.png"
            },
          {
                from: {
                    left:0,
                    top: 75,
                    width: 160,
                    height: 164
                },
                to : {
                    height : 216
                },
                thumbSrc: "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/thumb_kodaline_v3.png",
                albumSrc: "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/album_kodaline.png",
                titleSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/title_kodaline.png",
                infoSrc : "https://solutionoptimist-bucket.s3.amazonaws.com/kodaline/info_kodaline.png"
            }
        ];
    }
              
            
!
999px

Console