Skip to content

Instantly share code, notes, and snippets.

View bittu's full-sized avatar
🎯
Thinking...

Sandeep Kumar Vemula bittu

🎯
Thinking...
View GitHub Profile
@bittu
bittu / fireEvent.js
Created September 19, 2019 14:24
Programatically fire events on DOM elements
/**
* Function to fire events programatically
* on DOM elements
*
* Example:
* var domEl = document.getElementById('elementId')
* fireEvent(domEl, 'mouseover')
*
* @param {Node} el DOM element
* @param {String} Event name as String
@bittu
bittu / animate-elem-horizontal-scroll.js
Last active November 17, 2017 10:03
Scroll any element horizontally with smooth animation without any library.
const easeInQuad = (t, b, c, d) => {
return c * (t /= d) * t + b;
}
const requestAnimFrame = (() => {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function( callback ){ window.setTimeout(callback, 1000 / 60); };
})();
export const scrollElementLeftTo = (element, to, duration = 400, callback) => {
const move = (amount) => {
@bittu
bittu / animate-body-vertical-scroll.js
Last active October 16, 2017 08:47
Scroll document to any vertical position with smooth animation without any library.
const easeInQuad = (t, b, c, d) => {
return c * (t /= d) * t + b;
}
const requestAnimFrame = (() => {
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function( callback ){ window.setTimeout(callback, 1000 / 60); };
})();
export const scrollBodyTo = (to, duration = 400, callback) => {
const move = (amount) => {
@bittu
bittu / img-to-base64_webworkers.js
Last active August 4, 2019 17:14
Javascript Web Workers to process images to base64 data url without canvas using ES2015 Promises
let imgs = ['image1.jpg', 'image2.jpg']
let convertedImages = [];
let worker = new Worker('worker.js');
worker.addEventListener('message', function(event) {
convertedImages = event.data;
})
@bittu
bittu / img-to-base64.js
Created July 26, 2016 11:59
Javascript: Image to base64 data URL
function toDataUrl(src, type, callback) {
const img = new Image();
img.onload = function() {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.height = this.height;
canvas.width = this.width;
ctx.drawImage(this, 0, 0);
callback(canvas.toDataURL(type));