Created
November 17, 2014 14:41
-
-
Save morontt/8528c09900967e9bc67a to your computer and use it in GitHub Desktop.
temp-js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(function () { | |
| var hotel_image = $('#hotelImage'); | |
| var current_index = 0; | |
| var gal_height = 370; | |
| var gal_width = 570; | |
| var ratio = gal_width / gal_height; | |
| function imageHandler(current_element, url) { | |
| var image; | |
| var id; | |
| var x0, y0, x1, y1, t1, l1; | |
| if (!url) { | |
| image = $('img', current_element); | |
| id = parseInt(image.attr('id').replace(/^gallery_thumb_/, '')); | |
| } else { | |
| id = 0; | |
| } | |
| if (url || id !== current_index) { | |
| $('section.hotel .hotel-photo .thumbs a.cur').removeClass('cur'); | |
| if (current_element) { | |
| current_element.addClass('cur'); | |
| } | |
| var image_url = url || image.attr('src'); | |
| var original_image = document.createElement("IMG"); | |
| original_image.src = image_url; | |
| original_image.onload = function () { | |
| x0 = original_image.width; | |
| y0 = original_image.height; | |
| if (x0 !== 0 && y0 !== 0) { | |
| if (x0 < ratio * y0) { | |
| x1 = gal_width; | |
| y1 = gal_width * y0 / x0; | |
| t1 = -(y1 - gal_height) / 2; | |
| l1 = 0; | |
| } else { | |
| x1 = gal_height * x0 / y0; | |
| y1 = gal_height; | |
| t1 = 0; | |
| l1 = -(x1 - gal_width) / 2; | |
| } | |
| hotel_image.css({ | |
| 'width': x1 + 'px', | |
| 'height': y1 + 'px', | |
| 'top': t1 + 'px', | |
| 'left': l1 + 'px' | |
| }); | |
| } | |
| hotel_image.attr('src', image_url); | |
| }; | |
| current_index = id; | |
| } | |
| } | |
| if (hotel_image.length) { | |
| imageHandler(null, hotel_image.attr('src')); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment