dio-v
3/5/2015 - 6:32 AM

pop-in slider met wegklik cookie

pop-in slider met wegklik cookie

.slide-in {
    width:344px;
    background:#ffcc00;
    .box-shadow(0 10px 20px rgba(0,0,0,0.39));
    position:fixed;
    right:-355px;
    bottom:40px;
    z-index:999;
    .close{
        position:absolute;
        right:0px;
        top:0px;
        z-index:10000;
        display:block;
        width:20px;
        height:20px;
        text-align:center;
        line-height:20px;
        padding:0;
        background-color:#FFF;
        color:#000;
        &:hover{
            background-color:#000;
            color:#FFF;
        }
    }
    a{
	    color:#000;
	    text-decoration:none;
	    padding:10px 0 10px 10px;
	    display:block;
    }
    h2,h3{
        color:#000;
	    margin:0;
	    padding:0;
	    line-height:30px;
    }
    &:hover{
        .box-shadow(0 10px 20px rgba(0,0,0,0.49));
    }
}
    //pop-in slider
    //$('body').append('<div class="slide-in"><a href="#" class="close">X</a><a href="/contact.html"><h2>Op zoek naar de beste deal?</h2><h3>Voor de scherpste prijs, bel ons.</h3></a></div>');
    var popinOn = 'scrollBottom'; //opties: na x aantal milliseconden, 'scrollBottom'
    if ($.cookie('slide-in') !== 'false') {
        var vT = $('.slide-in');
        vT.find('.close').bind('click', function () {
            $.cookie('slide-in', 'false', { expires: 1 });
            vT.stop(true,true).animate({
                'right': vT.width() * -1 + 'px'
            }, 1000, 'swing', function () {
                vT.remove();
            });
            return false;
        });
        if ($.isNumeric(popinOn)) {
            setTimeout(function () {
                vT.animate({
                    'right': '0'
                }, 1000, 'swing');
            }, popinOn);
        } else if (popinOn === 'scrollBottom') {
            
            $(window).scroll(throttle2(function () {
                if ($(window).scrollTop() >= $(document).height() - $(window).height() - 300) {
                    console.log('1');
                    vT.animate({
                        'right': '0'
                    }, 1000, 'swing');
                }
            }, 200));

        }
    }
<div class="slide-in"><a href="#" class="close">X</a><a href="/contact.html"><h2>Op zoek naar de beste deal?</h2><h3>Voor de scherpste prijs, bel ons.</h3></a></div>
/*!
 * jQuery Cookie Plugin v1.4.1
 * https://github.com/carhartl/jquery-cookie
 *
 * Copyright 2006, 2014 Klaus Hartl
 * Released under the MIT license
 */
(function (factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD
        define(['jquery'], factory);
    } else if (typeof exports === 'object') {
        // CommonJS
        factory(require('jquery'));
    } else {
        // Browser globals
        factory(jQuery);
    }
}(function ($) {

    var pluses = /\+/g;

    function encode(s) {
        return config.raw ? s : encodeURIComponent(s);
    }

    function decode(s) {
        return config.raw ? s : decodeURIComponent(s);
    }

    function stringifyCookieValue(value) {
        return encode(config.json ? JSON.stringify(value) : String(value));
    }

    function parseCookieValue(s) {
        if (s.indexOf('"') === 0) {
            // This is a quoted cookie as according to RFC2068, unescape...
            s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
        }

        try {
            // Replace server-side written pluses with spaces.
            // If we can't decode the cookie, ignore it, it's unusable.
            // If we can't parse the cookie, ignore it, it's unusable.
            s = decodeURIComponent(s.replace(pluses, ' '));
            return config.json ? JSON.parse(s) : s;
        } catch (e) { }
    }

    function read(s, converter) {
        var value = config.raw ? s : parseCookieValue(s);
        return $.isFunction(converter) ? converter(value) : value;
    }

    var config = $.cookie = function (key, value, options) {

        // Write

        if (arguments.length > 1 && !$.isFunction(value)) {
            options = $.extend({}, config.defaults, options);

            if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setTime(+t + days * 864e+5);
            }

            return (document.cookie = [
				encode(key), '=', stringifyCookieValue(value),
				options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
				options.path ? '; path=' + options.path : '',
				options.domain ? '; domain=' + options.domain : '',
				options.secure ? '; secure' : ''
            ].join(''));
        }

        // Read

        var result = key ? undefined : {};

        // To prevent the for loop in the first place assign an empty array
        // in case there are no cookies at all. Also prevents odd result when
        // calling $.cookie().
        var cookies = document.cookie ? document.cookie.split('; ') : [];

        for (var i = 0, l = cookies.length; i < l; i++) {
            var parts = cookies[i].split('=');
            var name = decode(parts.shift());
            var cookie = parts.join('=');

            if (key && key === name) {
                // If second argument (value) is a function it's a converter...
                result = read(cookie, value);
                break;
            }

            // Prevent storing a cookie that we couldn't decode.
            if (!key && (cookie = read(cookie)) !== undefined) {
                result[name] = cookie;
            }
        }

        return result;
    };

    config.defaults = {};

    $.removeCookie = function (key, options) {
        if ($.cookie(key) === undefined) {
            return false;
        }

        // Must not alter options, thus extending a fresh object...
        $.cookie(key, '', $.extend({}, options, { expires: -1 }));
        return !$.cookie(key);
    };

}));

function throttle2(fn, threshhold, scope) {
    threshhold || (threshhold = 250);
    var last,
        deferTimer;
    return function () {
        var context = scope || this;

        var now = +new Date,
            args = arguments;
        if (last && now < last + threshhold) {
            // hold on to it
            clearTimeout(deferTimer);
            deferTimer = setTimeout(function () {
                last = now;
                fn.apply(context, args);
            }, threshhold);
        } else {
            last = now;
            fn.apply(context, args);
        }
    };
}