Other codes

Twitter likes Red Heart button CSS3 animation special effect

 Alibaba Cloud


This is a very cool simulation of the Twitter "Like" Red Heart button CSS3 animation special effect. The "Like" special effect uses a heart shaped button. When the user clicks the heart shaped button, the heart shaped button changes from gray to red, and at the same time, it will produce a fireworks explosion effect around the heart shaped button.

HTML Structure

The HTML structure of the "Like" red heart button is to place the heart button behind or below a hyperlink. Its HTML results are as follows:

Want to be here? contact us bar
 Maker host
  1.  < div class = "feed" id = "feed1" >
  2.    < p > JQuery Home < a href = " http://www.htmleaf.com/ " > http : //www.htmleaf.com/</a></p>
  3.    < div class = "heart" id = "like3" rel = "like" ></ div >
  4.    < div class = "likeCount" id = "likeCount3" > twenty-four </ div >
  5.  </ div >

CSS style

The whole "Like" fireworks explosion effect is actually achieved by continuous playback of background pictures. It uses a long Sprite picture, and then clicks the Red Heart button to play frame by frame. The following is the CSS style for displaying the first frame at the beginning:

  1.  .heart  {
  2.    background :  url ( images/web_heart_animation.png ) ;
  3.    background-position :  left ;
  4.    background-repeat :  no-repeat ;
  5.    height :  50px ;
  6.    width :  50px ;
  7.    cursor :  pointer ;
  8.    position :  absolute ;
  9.    left : -14px ;
  10.    background-size : 1450px ; //Actual background picture size 2900px
  11.  }
  12.  .heart : hover {
  13.    background-position :  right ; //Display the last red heart frame
  14.  }
  15.  .likeCount {
  16.    margin-top :  13px ;
  17.    margin-left :  28px ;
  18.    font-size :  16px ;
  19.    color :  #999999
  20.  }

The following code is to play the red heart background picture frame by frame, which is completed using CSS3 keyframe frame animation.

  1.  @-webkit-keyframes heartBlast {
  2.    0%  { background-position :  left ; }
  3.    100%  { background-position :  right ; }
  4.  }
  5.   
  6.  @keyframes heartBlast {
  7.    0%  { background-position :  left ; }
  8.    100%  { background-position :  right ; }
  9.  }
  10.   
  11.  .heartAnimation  {
  12.  -webkit-animation-name : heartBlast ; //Webkit kernel browser
  13.    animation-name : heartBlast ;
  14.  -webkit-animation-duration :  .8s ;
  15.    animation-duration :  .8s ;
  16.  -webkit-animation-iteration-count :  one ;
  17.    animation-iteration-count :  one ;
  18.  -webkit-animation-timing-function :  steps ( twenty-eight ) ; //Of twenty-eight Background picture frames
  19.    animation-timing-function :  steps ( twenty-eight ) ;
  20.    background-position :  right ;
  21.  }

JavaScript

In this "Like" Red Heart animation effect, jQuery code is used to link the Red Heart button with the corresponding total number of likes when clicked. You can use ajax to operate the database. When the user likes, the total quantity will be increased by 1, and when the user cancels the like, the total quantity will be decreased by 1.

  1.  < script >
  2.  $ ( document ) . ready ( function ( ) {
  3.  $ ( 'body' ) . on ( "click" , '.heart' , function ( ) {
  4.      var A = $ ( this ) . attr ( "id" ) ;
  5.      var B = A . split ( "like" ) ;  //splitting like1 to 1
  6.      var messageID = B [ one ] ;
  7.  $ ( this ) . css ( "background-position" , "" )
  8.      var D = $ ( this ) . attr ( "rel" ) ;
  9.   
  10.  $ . ajax ( {
  11.  type :  "POST" ,
  12.  url :  "message_like_ajax.php" ,
  13.  data : dataString ,
  14.  cache :  false ,
  15.  success :  function ( data ) {
  16.  $ ( "#likeCount" + messageID ) . html ( data ) ;
  17.        if ( D ===  'like' )  {
  18.  $ ( this ) . addClass ( "heartAnimation" ) . attr ( "rel" , "unlike" ) ;  //applying animation class
  19.        }
  20.        else {
  21.  $ ( this ) . removeClass ( "heartAnimation" ) . attr ( "rel" , "like" ) ;
  22.  $ ( this ) . css ( "background-position" , "left" ) ;
  23.        }
  24.      } ) ;  //ajax end
  25.   
  26.    } ) ; //heart click end
  27.   
  28.  } ) ;
  29.  </script>

Twitter likes Red Heart button CSS3 animation special effect

1753 people have bought
View Demo Upgrade VIP Buy Now

Demo Address Download address
Collection
fabulous ( forty-seven )

Post reply

Hot selling template

Ashade - Works exhibition photo album WordPress Chinese theme
 LensNews

This site accepts WordPress/PbootCMS/DedeCMS, etc
System construction, imitation, development, customization and other services!