Skip to content

Instantly share code, notes, and snippets.

@amirrajabi
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirrajabi/0531b65d191ecd92ea3e to your computer and use it in GitHub Desktop.
Save amirrajabi/0531b65d191ecd92ea3e to your computer and use it in GitHub Desktop.
/*
** for using Dynamic API, you should load jquery!
*/
// vars-----------------------------------------------------------
var winWidth = $(window).width(),
mobileWidth = 750;
//----------------------------------------------------------------
// list of function-----------------------------------------------
setHeight('featured-coffee-tea', winWidth, mobileWidth);
gotoScroll('goto', 1);
//----------------------------------------------------------------
// general resize cal function -----------------------------------
$( window ).resize(function() {
winWidth = $(window).width();
setHeight('featured-coffee-tea', winWidth, mobileWidth);
});
//----------------------------------------------------------------
//----------------------------------------------------------------
/*
** this API find list of same class name elements and find max height, after that set the max for all elements.
** it does not work for mobile size, because in mobile size all elements are vertical.
** using : setHeight('class name : string', Windows Width : number, Mobile breck Point : number);
** example : setHeight('test-element', 1024, 768);
*/
function setHeight(){
var listHeight = [],
maxHeight;
if(arguments[1] >= arguments[2]) {
$('.' + arguments[0]).each(
function () {
$(this).removeAttr("style");
listHeight.push($(this).height());
maxHeight = Math.max.apply(Math, listHeight);
$(this).css("min-height", maxHeight + "px");
}
);
}else{
$('.' + arguments[0]).each(
function () {
$(this).removeAttr("style");
}
);
}
}
//----------------------------------------------------------------
//----------------------------------------------------------------
/*
** this API is for scrolling to top of elements with animation.
** getting all vars on URL and find var of key and start scrolling
** using : gotoScroll('key' : string, speed : number); [key is id att on HTML element]
** example : gotoScroll('article', 2);
*/
function gotoScroll(){
var scrollId = window.location.search.substr(1),
vars = scrollId.split("&");
for(var i = 0; i < vars.length; i++){
var key = vars[i].split("=");
if (key[0] === arguments[0])
{
$('html, body').animate({
scrollTop: $("#"+key[1]).offset().top
}, arguments[1]*1000);
break;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment