Skip to content

Instantly share code, notes, and snippets.

View Rafailong's full-sized avatar
🤠

ravila Rafailong

🤠
  • Mexico
View GitHub Profile
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:31
Automatically load content on scroll
var loading = false;
$(window).scroll(function(){
if((($(window).scrollTop()+$(window).height())+250)>=$(document).height()){
if(!loading){
loading = true;
$('#loadingbar').css("display","block");
$.get("load.php?start="+$('#loaded_max').val(), function(loaded){
$('body').append(loaded);
$('#loaded_max').val(parseInt($('#loaded_max').val())+50);
$('#loadingbar').css("display","none");
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:30
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){
<input type="password" name="pass" id="pass" />
<span id="passstrength"></span>
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:28
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,
});
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:26
Open external links in a new tab/window
$('a').each(function() {
var a = new RegExp('/' + window.location.host + '/');
if(!a.test(this.href)) {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
});
}
});
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:26
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");
});
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:24
Partial page refresh
setInterval(function() {
$("#refresh").load(location.href+" #refresh>*","");
}, 10000); // milliseconds to wait
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:23
Equal height columns
var maxheight = 0;
$("div.col").each(function(){
if($(this).height() > maxheight) { maxheight = $(this).height(); }
});
$("div.col").height(maxheight);
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:22
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');
@Rafailong
Rafailong / script.js
Created January 29, 2014 18:21
Smooth scrolling to top of page
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});