Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function () {
- // Cesty
- var classBase = '.orbit';
- var classMove = classBase + ' .move';
- var classZoom = classBase + ' .zoom';
- var classItem = classBase + ' .item';
- var classSource = classBase + ' .source';
- var classMask = classBase + ' .mask';
- // Nastaveni
- // Rozmery
- var baseWidth = 800;
- var baseHeight = 400;
- // Limit zoomu
- var zoomInLimit = 200;
- var zoomOutLimit = 50;
- // Rychlost zoomu
- var zoomSpeed = 20;
- // Vychozi obrazek
- var startImageIndex = 40; // Pokud je vetsi nez posledni indexovany, nastavi se na 0
- // Vychozi stavy eventu
- var isMouseWheelUp, isMouseWheelDown, isMouseLeftDown, isMouseRightDown, isMouseMove, isMouseMoveLeft, isMouseMoveRight, mouseMovePrev;
- // CSS
- $(classBase).css({
- 'width' : baseWidth,
- 'height' : baseHeight,
- 'position' : 'relative',
- 'overflow' : 'hidden',
- });
- $(classZoom + ', ' + classMove).css({
- 'width' : '100%',
- 'height' : '100%',
- 'position' : 'absolute',
- 'left' : 0,
- 'top' : 0,
- });
- $(classItem + ' img').hide();
- $(classSource).hide();
- // Prvni a posledni obrazek
- var firstImageIndex = 0;
- var lastImageIndex = 0;
- // Index obrazku
- $(classSource + ' img').each(function(index, value) {
- lastImageIndex++; // Aktualizace posledniho obrazku
- $(this).attr('id', 'orbit-index-'+index);
- });
- // Prvni aktivni obrazek
- var activeImageIndex = ((startImageIndex !== 0 && startImageIndex <= lastImageIndex) ? startImageIndex : firstImageIndex);
- var firstImageSrc = $(classSource + ' img#orbit-index-'+activeImageIndex+'').attr('src');
- // Nezbytne HTML
- $(classBase).append('<div class="move"><div class="zoom"><div class="item" style="background-image:url('+firstImageSrc+');"><img src="'+firstImageSrc+'"></div></div></div>');
- // Funkce rotace
- function orbitRotate(data) {
- // Aktivni obrazek
- var activeImageSrc = $(classSource + ' img#orbit-index-'+activeImageIndex+'').attr('src');
- // Dalsi
- if(data == 'next') {
- if(activeImageIndex == lastImageIndex) {
- activeImageIndex = firstImageIndex;
- } else {
- activeImageIndex++;
- }
- }
- // Predchozi
- if(data == 'prev') {
- if(activeImageIndex == firstImageIndex) {
- activeImageIndex = lastImageIndex;
- } else {
- activeImageIndex--;
- }
- }
- $(classItem).css('background-image', 'url('+activeImageSrc+')');
- $(classItem + ' img').attr('src', activeImageSrc);
- }
- // Funkce priblizeni a oddaleni
- function orbitZoom(data) {
- // Kontrola nastaveni
- if(zoomInLimit < 100) zoomInLimit = 100;
- if(zoomOutLimit > 100) zoomInLimit = 100;
- // Puvodni velikost
- var origWidth = $(classZoom).parent().width();
- var origHeight = $(classZoom).parent().height();
- // Stavajici velikost
- var curWidth = $(classZoom).width();
- var curHeight = $(classZoom).height();
- // Koeficient rychlosti
- var cWidth = (curWidth / zoomSpeed);
- var cHeight = (curHeight / zoomSpeed);
- // Maxinalni, minimalni sirka a vyska
- var maxWidth = ((origWidth / 100) * zoomInLimit);
- var maxHeight = ((origHeight / 100) * zoomInLimit);
- var minWidth = ((origWidth / 100) * zoomOutLimit);
- var minHeight = ((origHeight / 100) * zoomOutLimit);
- // Pusteni dle smeru
- if(data == 'in') {
- curWidth = Math.round(curWidth + cWidth);
- curHeight = Math.round(curHeight + cHeight);
- }
- if(data == 'out') {
- curWidth = Math.round(curWidth - cWidth);
- curHeight = Math.round(curHeight - cHeight);
- }
- // Kontrola a zapis CSS
- if (maxWidth > curWidth && maxHeight > curHeight && minWidth < curWidth && minHeight < curHeight) {
- $(classZoom).css({
- 'width' : curWidth,
- 'height' : curHeight,
- 'left' : '50%',
- 'top' : '50%',
- 'margin-left' : -(curWidth / 2),
- 'margin-top' : -(curHeight / 2),
- });
- }
- }
- // Funkce pohyb
- function orbitMove(pageX, pageY) {
- $(classMove).css({
- 'left' : pageX - $(this).outerHeight() / 2,
- 'top' : pageY - $(this).outerHeight() / 2,
- });
- }
- // Event (mousewheel)
- $(classBase).on('mousewheel DOMMouseScroll wheel', function(e){
- // Plneni promennych dle cinosti
- if(e.type == 'mousewheel' || e.type == 'wheel') { // IE, Safari, Chrome, Opera
- if(e.originalEvent.wheelDelta < 0) {
- isMouseWheelDown = true;
- isMouseWheelUp = false;
- } else if (e.originalEvent.wheelDelta > 0) {
- isMouseWheelUp = true;
- isMouseWheelDown = false;
- }
- }
- if(e.type == 'DOMMouseScroll') { // Firefox
- if(e.originalEvent.detail > 0) {
- isMouseWheelDown = true;
- isMouseWheelUp = false;
- } else if (e.originalEvent.detail < 0) {
- isMouseWheelUp = true;
- isMouseWheelDown = false;
- }
- }
- // Vynulovani promennych pri necinosti
- clearTimeout($.data(this, 'stopTimer'));
- $.data(this, 'stopTimer', setTimeout(function() {
- isMouseWheelUp = false;
- isMouseWheelDown = false;
- }, 100));
- // Spousteni funkci
- if(isMouseWheelUp == true) orbitZoom('in');
- if(isMouseWheelDown == true) orbitZoom('out');
- });
- // Event (mousewheel)
- $(classBase).on('mousedown mouseup mousemove contextmenu', function(e){
- // Mousedown, mouseup
- if(e.type == 'mousedown') {
- if(e.which == 1) isMouseLeftDown = true;
- if(e.which == 3) isMouseRightDown = true;
- }
- if(e.type == 'mouseup') {
- if(e.which == 1) isMouseLeftDown = false;
- if(e.which == 3) isMouseRightDown = false;
- }
- if(e.type == 'mousemove') {
- isMouseMove = true;
- if(mouseMovePrev < e.pageX) {
- isMouseMoveLeft = false;
- isMouseMoveRight = true;
- } else {
- isMouseMoveLeft = true;
- isMouseMoveRight = false;
- }
- mouseMovePrev = e.pageX;
- // Vynulovani promennych pri necinosti
- clearTimeout($.data(this, 'stopTimer'));
- $.data(this, 'stopTimer', setTimeout(function() {
- isMouseMove = false;
- isMouseMoveLeft = false;
- isMouseMoveRight = false;
- }, 100));
- }
- if(e.type == 'contextmenu') {
- return false;
- }
- // Spousteni funkci
- if(isMouseLeftDown && isMouseMoveLeft) orbitRotate('next');
- if(isMouseLeftDown && isMouseMoveRight) orbitRotate('prev');
- // if(isMouseRightDown && isMouseMove) orbitMove(e.pageX, e.pageY);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement