Skip to content

Instantly share code, notes, and snippets.

@quawn
quawn / div-viewport.js
Last active January 4, 2016 03:19
JS: Div full Width/Height of viewport with jQuery
// global vars
var winWidth = $(window).width();
var winHeight = $(window).height();
// set initial div height / width
$('div').css({
'width': winWidth,
'height': winHeight,
});
@quawn
quawn / clone-table-header.js
Last active January 4, 2016 03:19
JS: Clone table header to the bottom of table
var $tfoot = $('<tfoot></tfoot>');
$($('thead').clone(true, true).children().get().reverse()).each(function(){
$tfoot.append($(this));
});
$tfoot.insertAfter('table thead');
@quawn
quawn / img-resizer.js
Last active January 4, 2016 03:19
JS: Image resizing using jQuery
$(window).bind("load", function() {
// IMAGE RESIZE
$('#product_cat_list img').each(function() {
var maxWidth = 120;
var maxHeight = 120;
var ratio = 0;
var width = $(this).width();
var height = $(this).height();
if(width > maxWidth){
@quawn
quawn / form.html
Last active January 4, 2016 03:19
JS: Test password strength
<input type="password" name="pass" id="pass" />
<span id="passstrength"></span>
@quawn
quawn / content-loader.js
Last active January 4, 2016 03:19
JS: Load external content
$("#content").load("somefile.html", function(response, status, xhr) {
// error handling
if(status == "error") {
$("#content").html("An error occured: " + xhr.status + " " + xhr.statusText);
}
});
@quawn
quawn / img-loaded-checker.js
Last active January 4, 2016 03:19
JS: Check if an image is loaded
var imgsrc = 'img/image1.png';
$('<img/>').load(function () {
alert('image loaded');
}).error(function () {
alert('error loading image');
}).attr('src', imgsrc);
@quawn
quawn / sorter.js
Last active January 4, 2016 03:19
JS: Sort a list alphabetically
$(function() {
$.fn.sortList = function() {
var mylist = $(this);
var listitems = $('li', mylist).get();
listitems.sort(function(a, b) {
var compA = $(a).text().toUpperCase();
var compB = $(b).text().toUpperCase();
return (compA < compB) ? -1 : 1;
});
$.each(listitems, function(i, itm) {
@quawn
quawn / zebra.js
Last active January 4, 2016 03:19
JS: Table Stripes (Zebra)
$(document).ready(function(){
$("table tr:even").addClass('stripe');
});
@quawn
quawn / style.css
Last active March 10, 2017 14:58
CSS: Block text gradient colour
background: -webkit-gradient(linear,left top,left bottom,from(#ff0052),to(#8e2b88));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
@quawn
quawn / gist:8560663
Last active March 10, 2017 15:03
JS: Preload images
$.preloadImages = function() {
for(var i = 0; i<arguments.length; i++) {
$("<img />").attr("src", arguments[i]);
}
}
$(document).ready(function() {
$.preloadImages("hoverimage1.jpg","hoverimage2.jpg");
});