cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              
<a href="#" class="">
  <svg class="heart"></svg>
</a>
<a href="#" class="active">
  <svg class="thumb-up"></svg>
</a>
<a href="#" class="">
  <svg class="thumb-down"></svg>
</a>

            
          
!
            
              a {
  text-decoration: none;
}

.heart #circle {
    fill: silver;
}

.active .heart #circle {
    fill: url(#heart-gradient);
}

.thumb-up, .thumb-down, .heart {
  width:100px;
  height:100px;
}

            
          
!
            
              var Thumb = function(selector, upDown){
    this.el = document.querySelector(selector);
    var _this = this;
    this.init = function(){
        Snap.load("https://res.cloudinary.com/noefalque/image/upload/v1492007173/thumb"+upDown+".svg", function(data){
            Snap(selector).append(data);

            // init elements :
            var s = Snap(selector);
            if(_this.el.parentElement.classList.contains("active")) {
                s.select("#circle-color").attr({transform: "scale(1)"});
                var thumbBackup = s.select("#thumb-hidden").attr("d");
                s.select("#thumb-hidden").attr({d: s.select("#thumb").attr("d")});
                s.select("#thumb").attr({d: thumbBackup, transform: "translateX(-50%)"});
            }
            else {
                s.select("#circle-color").attr({transform: "translate(40, 40) scale(0)"});
                s.select("#thumb-hidden").attr({transform: "translateX(-50%)"});
            }

            _this.el.addEventListener("click", function(){
                // anims:
                if(_this.el.parentElement.classList.contains("active"))
                    _this.unThumbAnim();
                else
                    _this.thumbAnim();
            });
        });
    }
    var _this = this;
    this.thumbAnim = function(){
        var s = Snap(selector);
        var thumb = s.select("#thumb");
        var thumbHidden = s.select("#thumb-hidden");
        var thumbBackup = thumbHidden.attr("d");
        var circleGrey = s.select("#circle-grey");
        var circleBlue = s.select("#circle-color");
        var explosion1 = s.select("#explosion-1");
        var explosion2 = s.select("#explosion-2");
        var explosion1Backup = s.select("#explosion-1").attr("d");
        circleGrey.animate({transform:"scale(0.9) translate(3, 3)"}, 200, mina.ease);
        thumb.animate({transform:"translate(40, 40) scale(0)"}, 200, mina.ease, function(){
            thumbHidden.animate({transform:"translateX(-20%)"}, 400, mina.ease, function(){
                var rot = upDown=="down" ? 3 : -3;
                var tslt = upDown=="down" ? -5 : -15;
                thumbHidden.animate({d: thumb.attr("d"), transform:"rotate("+rot+") translate("+tslt+", "+tslt+") scale(1.2)"}, 400, mina.easein, function(){
                    thumbHidden.animate({transform:"translate(0) scale(1)"}, 200, mina.easein, function(){
                        thumb.attr({d: thumbBackup});//reinit
                    });
                });
            });
            circleBlue.animate({transform: "scale(1.2) translate(-8, -8)"}, 200, function(){
                circleBlue.animate({transform:"scale(1)"}, 300, mina.ease);
                _this.el.parentElement.classList.add("active");
            });
            explosion1.animate({d: explosion2.attr("d"), opacity: "0"}, 1000, mina.easein, function(){
                explosion1.attr({d: explosion1Backup, opacity: "1"});//reinit
            });
        });
    }
    this.unThumbAnim = function(){
        var s = Snap(selector);
        var thumb = s.select("#thumb");
        var thumbHidden = s.select("#thumb-hidden");
        var thumbBackup = thumbHidden.attr("d");
        var circleBlue = s.select("#circle-color");
        var circleGrey = s.select("#circle-grey");
        circleBlue.animate({transform: "translate(40, 40) scale(0)"}, 200, mina.ease);
        thumbHidden.animate({d: thumb.attr("d")}, 700, mina.ease, function(){
            thumbHidden.animate({d: thumb.attr("d"), transform: "translate(-50)"}, 200, mina.ease);
            thumb.attr({d: thumbBackup, transform: "translate(50)"});
            thumb.animate({transform: "scale(1)", opacity: 1}, 200, mina.ease);
        });
        _this.el.parentElement.classList.remove("active");
    }
    this.init();
}

// instanciate thumbs:
var thumbs = document.querySelectorAll("[class^='thumb']");
for(var i=0; i<thumbs.length; i++){
    thumbs[i].classList.add("thumb-"+i);
    thumbs[i] = new Thumb(
        ".thumb-"+i,
        thumbs[i].classList.contains("thumb-up") ? "up" : "down"
    );
}


var Heart = function(selector){
    this.el = document.querySelector(selector);
    var _this = this;
    this.init = function(){
        Snap.load("https://res.cloudinary.com/noefalque/image/upload/v1492007173/heart.svg", function(data){
            Snap(selector).append(data);
            _this.el.addEventListener("click", function(){
                if(_this.el.parentElement.classList.contains("active"))
                    _this.unFavAnim();
                else
                    _this.favAnim();
            });
        });
    }
    var _this = this;
    this.favAnim = function(){
        var s = Snap(selector);
        var heart = s.select("#heart");
        var circle = s.select("#circle");
        var explosion1 = s.select("#explosion-1");
        var explosion1Backup = s.select("#explosion-1").attr("d");
        var explosion2 = s.select("#explosion-2");
        circle.animate({transform:"scale(0.9) translate(3, 3)"}, 200, mina.ease);
        heart.animate({transform:"scale(0.5) translate(30, 30)"}, 200, mina.ease, function(){
            circle.animate({transform:"scale(1.2) translate(-8, -8)"}, 300);
            heart.animate({transform:"scale(1.8) translate(-20, -20)"}, 200, mina.easein, function(){
                heart.animate({transform:"scale(1)"}, 300, mina.ease);
                circle.animate({transform:"scale(1)"}, 500, mina.ease); _this.el.parentElement.classList.add("active");
            });
            explosion1.animate({d: explosion2.attr("d"), opacity: "0"}, 700, mina.easein, function(){//reinit
                explosion1.attr({d: explosion1Backup, opacity: "1"});
            });
        });
    }
    this.unFavAnim = function(){
        var s = Snap(selector);
        var heart = s.select("#heart");
        var heartBackup = s.select("#heart").attr("d");
        var heart2 = s.select("#heart-broken");
        heart.animate({d: heart2.attr("d")}, 200, mina.ease, function(){
            setTimeout(function(){
                heart.animate({d: heartBackup}, 200, mina.ease, function(){
                    _this.el.parentElement.classList.remove("active");
                });
            }, 500);
        });
    }
    this.init();
}

//instanciate hearts:
var hearts = document.querySelectorAll(".heart");
for(var i=0; i<hearts.length; i++){
    hearts[i].classList.add("heart-"+i)
    hearts[i] = new Heart(".heart-"+i);
}

            
          
!
999px
Loading ..................

Console