< div class = "feed" id = "feed1" >
< p > JQuery Home < a href = " http://www.htmleaf.com/ " > http : //www.htmleaf.com/</a></p>
< div class = "heart" id = "like3" rel = "like" ></ div >
< div class = "likeCount" id = "likeCount3" > twenty-four </ div >
</ div >
.heart {
background : url ( images/web_heart_animation.png ) ;
background-position : left ;
background-repeat : no-repeat ;
height : 50px ;
width : 50px ;
cursor : pointer ;
position : absolute ;
left : -14px ;
background-size : 1450px ; //Actual background picture size 2900px
}
.heart : hover {
background-position : right ; //Display the last red heart frame
}
.likeCount {
margin-top : 13px ;
margin-left : 28px ;
font-size : 16px ;
color : #999999
}
@-webkit-keyframes heartBlast {
0% { background-position : left ; }
100% { background-position : right ; }
}
@keyframes heartBlast {
0% { background-position : left ; }
100% { background-position : right ; }
}
.heartAnimation {
-webkit-animation-name : heartBlast ; //Webkit kernel browser
animation-name : heartBlast ;
-webkit-animation-duration : .8s ;
animation-duration : .8s ;
-webkit-animation-iteration-count : one ;
animation-iteration-count : one ;
-webkit-animation-timing-function : steps ( twenty-eight ) ; //Of twenty-eight Background picture frames
animation-timing-function : steps ( twenty-eight ) ;
background-position : right ;
}
< script >
$ ( document ) . ready ( function ( ) {
$ ( 'body' ) . on ( "click" , '.heart' , function ( ) {
var A = $ ( this ) . attr ( "id" ) ;
var B = A . split ( "like" ) ; //splitting like1 to 1
var messageID = B [ one ] ;
$ ( this ) . css ( "background-position" , "" )
var D = $ ( this ) . attr ( "rel" ) ;
$ . ajax ( {
type : "POST" ,
url : "message_like_ajax.php" ,
data : dataString ,
cache : false ,
success : function ( data ) {
$ ( "#likeCount" + messageID ) . html ( data ) ;
if ( D === 'like' ) {
$ ( this ) . addClass ( "heartAnimation" ) . attr ( "rel" , "unlike" ) ; //applying animation class
}
else {
$ ( this ) . removeClass ( "heartAnimation" ) . attr ( "rel" , "like" ) ;
$ ( this ) . css ( "background-position" , "left" ) ;
}
} ) ; //ajax end
} ) ; //heart click end
} ) ;
</script>
|
|