Created
March 2, 2020 14:56
-
-
Save iankit3/cbfe081243f67be02f277f94bc7185c1 to your computer and use it in GitHub Desktop.
Medium Clap Like feature // source https://jsbin.com/zujavim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Medium Clap Like feature</title> | |
<style id="jsbin-css"> | |
button.clap{ | |
width: 30px; | |
height: 30px; | |
background: no-repeat center/80% url('https://image.flaticon.com/icons/png/512/109/109638.png') #fff; | |
background-size: 70%; | |
box-shadow: 0px 0px 3px 2px #dcdcdc; | |
border-radius: 50%; | |
transition: border-width 0.5s; | |
box-sizing: border-box; | |
} | |
button.clap:hover{ | |
box-shadow: 0px 0px 6px 4px #dcdcdc; | |
} | |
</style> | |
</head> | |
<body> | |
<script src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script> | |
<button id="clap" class="clap"> | |
</button> | |
<script id="jsbin-javascript"> | |
"use strict"; | |
var clapBtn = document.getElementById("clap"); | |
var clapOb = Rx.Observable.fromEvent(clapBtn, "click").map(function (ev, x) { | |
return ++x; | |
}).throttle(function (ev) { | |
return Rx.Observable.interval(1000); | |
}); | |
//log can be a api call | |
var log = function log(x) { | |
console.log(x); | |
}; | |
clapOb.subscribe(function (ev) { | |
return log(ev); | |
}); | |
</script> | |
<script id="jsbin-source-css" type="text/css">button.clap{ | |
width: 30px; | |
height: 30px; | |
background: no-repeat center/80% url('https://image.flaticon.com/icons/png/512/109/109638.png') #fff; | |
background-size: 70%; | |
box-shadow: 0px 0px 3px 2px #dcdcdc; | |
border-radius: 50%; | |
transition: border-width 0.5s; | |
box-sizing: border-box; | |
} | |
button.clap:hover{ | |
box-shadow: 0px 0px 6px 4px #dcdcdc; | |
}</script> | |
<script id="jsbin-source-javascript" type="text/javascript">var clapBtn = document.getElementById("clap"); | |
var clapOb = Rx.Observable.fromEvent(clapBtn , "click") | |
.map((ev,x) => { | |
return ++x; | |
}) | |
.throttle(ev => Rx.Observable.interval(1000)) | |
//log can be a api call | |
const log = (x) => { | |
console.log(x); | |
} | |
clapOb.subscribe(ev => log(ev));</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
button.clap{ | |
width: 30px; | |
height: 30px; | |
background: no-repeat center/80% url('https://image.flaticon.com/icons/png/512/109/109638.png') #fff; | |
background-size: 70%; | |
box-shadow: 0px 0px 3px 2px #dcdcdc; | |
border-radius: 50%; | |
transition: border-width 0.5s; | |
box-sizing: border-box; | |
} | |
button.clap:hover{ | |
box-shadow: 0px 0px 6px 4px #dcdcdc; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var clapBtn = document.getElementById("clap"); | |
var clapOb = Rx.Observable.fromEvent(clapBtn, "click").map(function (ev, x) { | |
return ++x; | |
}).throttle(function (ev) { | |
return Rx.Observable.interval(1000); | |
}); | |
//log can be a api call | |
var log = function log(x) { | |
console.log(x); | |
}; | |
clapOb.subscribe(function (ev) { | |
return log(ev); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example use of Throttle
https://jsbin.com/zujavim/10/edit?js,console,output