Pdf/BaladeNature/Js/balade_nature.js
author Patrick PIERRE <patrick.pierre@prismallia.fr>
mar., 23 avril 2013 08:31:19 +0200
changeset 94 d8344a68c91f
parent 74 58e48a5c5ca2
child 124 f0f5895259d9
permissions -rw-r--r--
Nouveaux hotspots
patrick@17
     1
// $Id$
patrick@17
     2
// balade_nature
patrick@17
     3
patrick@17
     4
var text = null;
patrick@17
     5
var spot = null;
patrick@17
     6
var box = null;
patrick@17
     7
var boxProperty = '';
patrick@17
     8
patrick@17
     9
patrick@17
    10
window.addEvent('domready', function(){
Patrick@74
    11
    // Hotspots
patrick@17
    12
    (function initialize() {
Patrick@74
    13
        $$(".pdocHotspot").each(function(hotspot) {
patrick@94
    14
            var spot = $(hotspot.get('id') + "s")
patrick@94
    15
            var scenario = hotspot.getElement("span");
patrick@94
    16
            if (spot && scenario) {
Patrick@74
    17
                hotspot.addEvent("click", function() {
patrick@94
    18
                    var spot = $(this.get('id') + "s");
patrick@94
    19
                    if (spot.getChildren("img")) {
patrick@94
    20
                        spot.setStyles({"opacity": 1, "display": "block"});
patrick@94
    21
                    } else {
patrick@94
    22
                        spot.setStyles({"opacity": 0, "display": "block"});
patrick@94
    23
                        spot.tween("opacity", 1);
patrick@94
    24
                    }
Patrick@74
    25
                    this.setStyle("display", "none");
Patrick@74
    26
                    (function() {
patrick@94
    27
                        spot.setStyle("display", "none");
Patrick@74
    28
                        hotspot.setStyle("display", "block");
Patrick@74
    29
                    }).delay(12000);
Patrick@74
    30
                });
patrick@17
    31
patrick@94
    32
                spot.addEvent("click", function() {
Patrick@74
    33
                    this.setStyle("display", "none");
patrick@94
    34
                    $(this.get('id').substring(0, this.get('id').length-1))
Patrick@74
    35
                        .setStyle("display", "block");
Patrick@74
    36
                });
patrick@17
    37
            }
patrick@17
    38
        });
Patrick@74
    39
    }).delay(100);
patrick@17
    40
     
patrick@17
    41
    // Effect: glow
patrick@17
    42
    var effectGlow = $("effectGlow");
patrick@17
    43
    if (effectGlow) {
patrick@17
    44
        text = $("effectGlowText");
patrick@17
    45
        spot = $("effectGlowSpot");
patrick@17
    46
        box = $("effectGlowBox")
patrick@17
    47
        if (typeof box.style.webkitBoxShadow == 'string') {
patrick@17
    48
            boxProperty = 'webkitBoxShadow';
patrick@17
    49
        } else if (typeof box.style.MozBoxShadow == 'string') {
patrick@17
    50
            boxProperty = 'MozBoxShadow';
patrick@17
    51
        } else if (typeof box.style.boxShadow == 'string') {
patrick@17
    52
            boxProperty = 'boxShadow';
patrick@17
    53
        }
patrick@17
    54
patrick@17
    55
        if (text && spot && box) {
patrick@17
    56
            effectGlow.onmousemove = onMouseMove;
patrick@17
    57
            effectGlow.ontouchmove = function (e) {
patrick@17
    58
                e.preventDefault();
patrick@17
    59
                e.stopPropagation();
patrick@17
    60
                onMouseMove({clientX: e.touches[0].clientX, clientY: e.touches[0].clientY});
patrick@17
    61
            }
patrick@17
    62
        }
patrick@17
    63
    }
patrick@17
    64
});
patrick@17
    65
patrick@17
    66
patrick@17
    67
function onMouseMove(e) {
patrick@17
    68
    if (typeof e === 'undefined' || typeof e.clientX === 'undefined') {
patrick@17
    69
        return;
patrick@17
    70
    }
patrick@17
    71
    
patrick@17
    72
    var xm = (e.clientX - Math.floor(window.innerWidth / 2)) * 0.4;
patrick@17
    73
    var ym = (e.clientY - Math.floor(window.innerHeight / 3)) * 0.4;
patrick@17
    74
    var d = Math.round(Math.sqrt(xm*xm + ym*ym) / 5);
patrick@17
    75
    text.style.textShadow = -xm + 'px ' + -ym + 'px ' + (d + 10) + 'px black';
patrick@17
    76
    
patrick@17
    77
    if (boxProperty) {
patrick@17
    78
        box.style[boxProperty] = '0 ' + -ym + 'px ' + (d + 30) + 'px black';
patrick@17
    79
    }
patrick@17
    80
    
patrick@17
    81
    xm = e.clientX - Math.floor(window.innerWidth / 2);
patrick@17
    82
    ym = e.clientY - Math.floor(window.innerHeight / 2);
patrick@17
    83
    spot.style.backgroundPosition = xm + 'px ' + ym + 'px';
patrick@17
    84
}
patrick@17
    85