This time I will share jQuery Plugin and tutorial about Minimal Like / Dislike Button Plugin with jQuery – like-dislike, hope it will help you in programming stack.
like-dislike is a really simple jQuery plugin for generating a like button widget on your website that displays the number of users who liked / disliked each content.
How to use it:
1. Place jQuery library and the jQuery like-dislike plugin at the bottom of your webpage.
1 |
< script src = "//code.jquery.com/jquery-1.11.3.min.js" ></ script > |
2 |
< script src = "js/like-dislike.js" ></ script > |
2. Create like and dislike buttons on the webpage.
2 |
< button class = "like" >Like |
3 |
< span class = "likes" >0</ span > |
5 |
< button class = "dislike" >Dislike |
6 |
< span class = "dislikes" >0</ span > |
3. Call the function on the top element to active the plugin.
1 |
$( '#demo' ).likeDislike(); |
4. Auto-update like / dislike counters.
01 |
$( '#demo' ).likeDislike({ |
04 |
click: function (btnType, likes, dislikes, event) { |
05 |
var likesElem = $( this ).find( '.likes' ); |
06 |
var dislikedsElem = $( this ).find( '.dislikes' ); |
07 |
likesElem.text(parseInt(likesElem.text()) + likes); |
08 |
dislikedsElem.text(parseInt(dislikedsElem.text()) + dislikes); |
5. Advanced usage.
01 |
$( '#demo' ).likeDislike({ |
03 |
activeBtn: localStorage[ 'key' ]? localStorage[ 'key' ] : '' , |
04 |
click: function (btnType, likes, dislikes, event) { |
14 |
data: 'id=1' + '&likes=' + likes + '&dislikes=' + dislikes, |
15 |
success: function (data) { |
17 |
$(self).find( '.likes' ).text(data.likes); |
18 |
$(self).find( '.dislikes' ).text(data.dislikes); |
19 |
localStorage[ 'key' ] = btnType; |
6. Options and defaults.
01 |
$( '#demo' ).likeDislike({ |
08 |
dislikeBtnClass: 'dislike' , |
09 |
activeClass: 'active' , |
10 |
disableClass: 'disable' |
Change log:
2017-03-20
This awesome jQuery plugin is developed by uagrace. For more Advanced Usages, please check the demo page or visit the official website.