0

I used a Codrops article/experiment to create an interactive environment for a local group to use at their conferences. The problem with this is the default interaction is not very intuitive. The template used Flickity.js and what seems like classie.js to create this sliding interface I am having trouble with.

The page can be found here:

www.eyeconic.tv/ky-ffa/

Issue: The only way to activate the view-full is by clicking on the html element:

<h2 class=".stack-title">

// After the stack is active you should be able to activate the full view by clicking on the first .stack-item used to create the thumbnail below it. This entire div should be clickable. Users are touching everywhere all over the screen and not actually clicking the title for the desired action. I hope this makes sense.

In other words you should be able to click the stack-title and the image below the title of each stack to pull the stack into the full view mode on the screen. Then click the x or anywhere else on the screen to close the full view.

The following is located in main.js and the reference I found to create the events I am referring to.

//
function initEvents() {
        stacks.forEach(function(stack) {
            var titleEl = stack.querySelector('.stack-title');

            // expand/close the stack
            titleEl.addEventListener('click', function(ev) {
                ev.preventDefault();
                if( classie.has(stack, 'is-selected') ) { // current stack
                    if( classie.has(bodyEl, 'view-full') ) { // stack is opened
                        var closeStack = function() {
                            classie.remove(bodyEl, 'move-items');

                            onEndTransition(slider, function() {
                                classie.remove(bodyEl, 'view-full');
                                bodyEl.style.height = '';
                                flkty.bindDrag();
                                flkty.options.accessibility = true;
                                canMoveHeroImage = true;
                            });
                        };

                        // if the user scrolled down, let's first scroll all up before closing the stack.
                        var scrolled = scrollY();
                        if( scrolled > 0 ) {
                            smooth_scroll_to(isFirefox ? docElem : bodyEl || docElem, 0, 500).then(function() {
                                closeStack();
                            });
                        }
                        else {
                            closeStack();
                        }
                    }
                    else if( canOpen ) { // stack is closed
                        canMoveHeroImage = false;
                        classie.add(bodyEl, 'view-full');
                        setTimeout(function() { classie.add(bodyEl, 'move-items'); }, 25);
                        bodyEl.style.height = stack.offsetHeight + 'px';
                        flkty.unbindDrag();
                        flkty.options.accessibility = false;
                    }
                }
                else if( classie.has(stack, 'stack-prev') ) {
                    flkty.previous(true);
                }
                else if( classie.has(stack, 'stack-next') ) {
                    flkty.next(true);
                }
            });

            titleEl.addEventListener('mouseenter', function(ev) {
                if( classie.has(stack, 'is-selected') ) {
                    canMoveHeroImage = false;
                    imghero.style.WebkitTransform = 'perspective(1000px) translate3d(0,0,0) rotate3d(1,1,1,0deg)';
                    imghero.style.transform = 'perspective(1000px) translate3d(0,0,0) rotate3d(1,1,1,0deg)';
                }
            });

            titleEl.addEventListener('mouseleave', function(ev) {
                // if current stack and it's not opened..
                if( classie.has(stack, 'is-selected') && !classie.has(bodyEl, 'view-full') ) {
                    canMoveHeroImage = true;
                }
            });
        });

        window.addEventListener('mousemove', throttle(function(ev) {
            if( !canMoveHeroImage ) return false;
            var xVal = -1/(win.height/2)*ev.clientY + 1,
                yVal = 1/(win.width/2)*ev.clientX - 1,
                transX = 20/(win.width)*ev.clientX - 10,
                transY = 20/(win.height)*ev.clientY - 10,
                transZ = 100/(win.height)*ev.clientY - 50;

            imghero.style.WebkitTransform = 'perspective(1000px) translate3d(' + transX + 'px,' + transY + 'px,' + transZ + 'px) rotate3d(' + xVal + ',' + yVal + ',0,2deg)';
            imghero.style.transform = 'perspective(1000px) translate3d(' + transX + 'px,' + transY + 'px,' + transZ + 'px) rotate3d(' + xVal + ',' + yVal + ',0,2deg)';
        }, 100));

        // window resize
        window.addEventListener( 'resize', throttle(function(ev) {
            // recalculate window width/height
            win = { width: window.innerWidth, height: window.innerHeight };
            // reset body height if stack is opened
            if( classie.has(bodyEl, 'view-full') ) { // stack is opened
                bodyEl.style.height = stacks[flkty.selectedIndex].offsetHeight + 'px';
            }
        }, 50));

        // Flickity events:
        flkty.on('cellSelect', function() {
            canOpen = false;
            classie.remove(bodyEl, 'item-clickable');

            var prevStack = stacksWrapper.querySelector('.stack-prev'),
                nextStack = stacksWrapper.querySelector('.stack-next'),
                selidx = flkty.selectedIndex,
                cellsCount = flkty.cells.length,
                previdx = selidx > 0 ? selidx - 1 : cellsCount - 1;
                nextidx = selidx < cellsCount - 1 ? selidx + 1 : 0;

            if( prevStack ) {
                classie.remove(prevStack, 'stack-prev');
            }
            if( nextStack ) {
                classie.remove(nextStack, 'stack-next');    
            }

            classie.add(stacks[previdx], 'stack-prev');
            classie.add(stacks[nextidx], 'stack-next');

        });

        flkty.on('dragStart', function() {
            canOpen = false; 
            classie.remove(bodyEl, 'item-clickable');
        });

        flkty.on('settle', function() { 
            classie.add(bodyEl, 'item-clickable');
            canOpen = true; 
        });
    }

    init();

})();
  • From a quick glance at your code, it looks like you just need to add the same function that you have for the `click` event on the `stack-title` to the `.item` class. – Gary Storey Jul 16 '15 at 20:31
  • I tried to replace the .stack-title with the .item in the querySelector to see what happens, but this creates a mess in itself triggering the close function on the stack when the user interacts with a touch/click anywhere in the div. – leaninonlife Jul 16 '15 at 20:50
  • If I try this: `var titleEl = stack.querySelector('.stack-title, .item-first');` According to what I read, it will only grab the element that is found first in the document: "For multiple selectors, separate each selector with a comma. The returned element depends on which element that is first found in the document (See "More Examples")." If I just use the .item class I run into the aforementioned problem. I've tried to wrap them in a separate class before I posted on here and I got a null error returned by the querySelector in the console. @garystorey – leaninonlife Jul 16 '15 at 21:04

1 Answers1

0

I wrapped the title and the first stack item in a div class .touch-me and it worked fairly well. I had previously tried to do this and received an error. But I may have mistyped something because it only made sense.

ISSUE: It works on mouseclick, but it is not working with touch on windows. I have untested it in any other environment because it will be deployed on a windows touch screen.

Although I cannot tell the layer not to close on touch when you swipe or touch the header image for the stack.... I'm afraid I do not have the skillset to properly modify the logic in the javascript since I do not entirely understand the plugins being used.