Team:ETH Zurich/project/overview/grid
From 2014.igem.org
(Difference between revisions)
Line 2: | Line 2: | ||
<html> | <html> | ||
+ | <article id="article"> | ||
+ | <h1>Images in the Tooltip</h1> | ||
+ | <IMG SRC="/wiki/images/d/d9/ETH_Zurich_GridGlowing.png" usemap="#map" id="mapTest"> | ||
+ | <map id="map" name="map"> | ||
+ | <area shape="circle" title="" alt="" coords="281,26,17" href="javascript:alert('foo');" target="" id="age" class="showTip L1" /> | ||
+ | </map> | ||
- | |||
- | |||
- | |||
<script type="text/javascript"> | <script type="text/javascript"> | ||
- | + | (function($) { | |
- | + | function img(url) { | |
- | + | var i = new Image; | |
- | + | i.src = url; | |
- | + | return i; | |
- | + | ||
} | } | ||
+ | |||
+ | if ('naturalWidth' in (new Image)) { | ||
+ | $.fn.naturalWidth = function() { return this[0].naturalWidth; }; | ||
+ | $.fn.naturalHeight = function() { return this[0].naturalHeight; }; | ||
+ | return; | ||
+ | } | ||
+ | $.fn.naturalWidth = function() { return img(this[0].src).width; }; | ||
+ | $.fn.naturalHeight = function() { return img(this[0].src).height; }; | ||
+ | })(jQuery); | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||
- | } | + | function onWindowResize() |
+ | { | ||
+ | var curWidth = $(window).width(), | ||
+ | curHeight = $(window).height(), | ||
+ | checking=false; | ||
+ | if (checking) { | ||
+ | return; | ||
+ | } | ||
+ | checking = true; | ||
+ | window.setTimeout( | ||
+ | function() { | ||
+ | var newWidth = $(window).width(), | ||
+ | newHeight = $(window).height(); | ||
+ | if (!(newWidth !== curWidth || | ||
+ | newHeight !== curHeight)) { | ||
+ | resize(false); | ||
+ | } | ||
+ | checking=false; | ||
+ | }, 300); | ||
} | } | ||
- | + | function resize(initial) { | |
+ | if (!initial) | ||
+ | { | ||
+ | var container = $('#article'); | ||
+ | var imgWidth = container.width(); | ||
- | + | $( "#mapTest").each(function() { | |
- | + | $(this).css('height', 'auto', 'width', 'auto'); | |
+ | $(this).mapster('resize',Math.min(imgWidth, $(this).naturalWidth()) ,0,0); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
- | |||
- | |||
- | |||
- | + | $(document).ready(function(){ | |
- | + | $('#mapTest').mapster({ | |
+ | fillColor: '2C2F3D', | ||
+ | fillOpacity: 1 | ||
+ | /* clickNavigate: false , | ||
+ | stroke: true, | ||
+ | strokeColor: 'c2d8f1', | ||
+ | strokeOpacity: 0.9, | ||
+ | strokeWidth: 2, | ||
+ | clickNavigate: true */ | ||
+ | }); | ||
+ | |||
+ | |||
+ | $(window).resize( | ||
+ | function() | ||
+ | { | ||
+ | onWindowResize(); | ||
+ | }); | ||
+ | resize(true); | ||
+ | }); | ||
+ | </script> | ||
+ | |||
</article> | </article> |