Dongzhuoer (Talk | contribs) (Created page with " var debug = true; var igem = document.location.href.includes('https://2016.igem.org/'); //element is $(<img>), which is 100% embed in its parent. So aut...") |
Dongzhuoer (Talk | contribs) |
||
Line 1: | Line 1: | ||
− | + | var debug = true; | |
− | + | var igem = document.location.href.includes('https://2016.igem.org/'); | |
− | + | //element is inner jquery, $('.auto-adjust') is middle jquery. Inner jquery is 100% embed in its parent--middle jquery. So we just need to automatically adjust middle jquery accordingly to outer jquery | |
− | + | function auto_adjust() { | |
− | + | $('.auto-adjust-inner').each(function (index, value) { | |
− | + | var inner = $(value) | |
− | + | var middle = inner.parent(); | |
− | + | var outer = middle.parent(); | |
− | + | var ratio = inner.width() / inner.height(); | |
− | + | function impl() { | |
− | + | middle.width(outer.width()); | |
− | + | middle.height(outer.width() / ratio); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
+ | |||
+ | impl(); | ||
+ | window.addEventListener('resize', impl) | ||
+ | }) | ||
+ | } |
Revision as of 02:53, 20 August 2016
var debug = true; var igem = document.location.href.includes('https://2016.igem.org/'); //element is inner jquery, $('.auto-adjust') is middle jquery. Inner jquery is 100% embed in its parent--middle jquery. So we just need to automatically adjust middle jquery accordingly to outer jquery function auto_adjust() {
$('.auto-adjust-inner').each(function (index, value) { var inner = $(value) var middle = inner.parent(); var outer = middle.parent(); var ratio = inner.width() / inner.height();
function impl() { middle.width(outer.width()); middle.height(outer.width() / ratio); }
impl(); window.addEventListener('resize', impl) })
}