IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

jQuery Discussion :

Souci multiple options dans effet jquery parallax


Sujet :

jQuery

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Inscrit en
    Février 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Février 2012
    Messages : 14
    Par défaut Souci multiple options dans effet jquery parallax
    Bonjour
    j'essaye pour mon site de faire un effet parallax en suivant les conseils trouvés sur ce site: http://http://stephband.info/jparallax/

    Dans la page il est stipulé (si j'ai bien compris) que l'on peut attribuer des options différentes a certains éléments:

    In addition to the global options above, individual layers can be passed their own set of options as extra arguments:

    jQuery('.parallax-layer')
    .parallax(options, layer_0_options, layer_1_options, ... );

    As an example, to give the second layer a set xparallax value, but pass no options as default:

    jQuery('.parallax-layer')
    .parallax({}, {}, {xparallax: '200px'});

    A layer option object can have the properties xparallax, yparallax, xorigin, yorigin, width and height, with the same meanings as described above.
    Or je n'arrive pas à mettre ça en forme...comment distinguer les layer pour leur attribuer des options différentes?


    Le code des options est celui ci à l'origine:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    	var options = {
    	    	mouseport:	'body',    // jQuery object or selector of DOM node to use as mouse detector
    	    	xparallax:	true,      // boolean | 0-1 | 'npx' | 'n%' - Sets axis of reaction and by how much they react
    	    	yparallax:	true,      //
    	    	xorigin:		0.5,       // 0-1 - Sets default alignment. Only has effect when parallax values are something other than 1 (or true, or '100%')
    	    	yorigin:		0.5,       //
    	    	decay:			0.66,      // 0-1 (0 instant, 1 forever) - Sets rate of decay curve for catching up with target mouse position
    	    	frameDuration:	30,    // Int (milliseconds)
    	    	freezeClass:	'freeze' // String - Class added to layer when frozen
    	    },
     
    	    value = {
    	    	left: 0,
    	    	top: 0,
    	    	middle: 0.5,
    	    	center: 0.5,
    	    	right: 1,
    	    	bottom: 1
    	    },
     
    	    regex = {
    	    	px:			/^\d+\s?px$/,
    	    	percent:	/^\d+\s?%$/
    	    },
     
    	    frameEvent = 'frame.'+plugin,
     
    	    abs = Math.abs,
     
    	    pointer = [0, 0];
    J'avais écrit ça pour mettre une option différente:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    	var options = {
    	    	mouseport:	'body',    // jQuery object or selector of DOM node to use as mouse detector
    	    	xparallax:	true,      // boolean | 0-1 | 'npx' | 'n%' - Sets axis of reaction and by how much they react
    	    	yparallax:	true,      //
    	    	xorigin:		0.5,       // 0-1 - Sets default alignment. Only has effect when parallax values are something other than 1 (or true, or '100%')
    	    	yorigin:		0.5,       //
    	    	decay:			0.66,      // 0-1 (0 instant, 1 forever) - Sets rate of decay curve for catching up with target mouse position
    	    	frameDuration:	30,    // Int (milliseconds)
    	    	freezeClass:	'freeze' // String - Class added to layer when frozen
    	    },
     
    	    value = {
    	    	left: 0,
    	    	top: 0,
    	    	middle: 0.5,
    	    	center: 0.5,
    	    	right: 1,
    	    	bottom: 1
    	    },
     
    	    regex = {
    	    	px:			/^\d+\s?px$/,
    	    	percent:	/^\d+\s?%$/
    	    },
     
    	    frameEvent = 'frame.'+plugin,
     
    	    abs = Math.abs,
     
    	    pointer = [0, 0];
     
     
    	var layer_1_options = {
    	    	mouseport:	'body',    // jQuery object or selector of DOM node to use as mouse detector
    	    	xparallax:	true,      // boolean | 0-1 | 'npx' | 'n%' - Sets axis of reaction and by how much they react
    	    	yparallax:	true,      //
    	    	xorigin:		0.5,       // 0-1 - Sets default alignment. Only has effect when parallax values are something other than 1 (or true, or '100%')
    	    	yorigin:		0.7,       //
    	    	decay:			0.66,      // 0-1 (0 instant, 1 forever) - Sets rate of decay curve for catching up with target mouse position
    	    	frameDuration:	30,    // Int (milliseconds)
    	    	freezeClass:	'freeze' // String - Class added to layer when frozen
    	    },
     
    	    value = {
    	    	left: 0,
    	    	top: 0,
    	    	middle: 0.5,
    	    	center: 0.5,
    	    	right: 1,
    	    	bottom: 1
    	    },
     
    	    regex = {
    	    	px:			/^\d+\s?px$/,
    	    	percent:	/^\d+\s?%$/
    	    },
     
    	    frameEvent = 'frame.'+plugin,
     
    	    abs = Math.abs,
     
    	    pointer = [0, 0];


    et dans la page html j'avais mis ça pour l'image qui devait avoir des options différentes:
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    <div class="parallax-layer_1" style="width:1200px; height:170px;">
                <img src="images/logo3.png" alt="" style="position:absolute; top:10px; right:40;" />
            </div>
            </div>


    mais ça ne marche pas...

    Me suis-je bien fait comprendre?
    Je ne suis pas très calé, j'ai réussi a faire marcher le zaffaire mais là je bloque!
    Merci par avance à tous ceux qui pourront m'aider!!

  2. #2
    Rédacteur/Modérateur

    Avatar de SylvainPV
    Profil pro
    Inscrit en
    Novembre 2012
    Messages
    3 375
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2012
    Messages : 3 375
    Par défaut
    Bonjour,

    Peux-tu nous donner le code où tu appelles le plug-in avec .parallax() ? C'est le bout le plus important

  3. #3
    Membre averti
    Homme Profil pro
    Inscrit en
    Février 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Février 2012
    Messages : 14
    Par défaut
    oui pas de soucis! c'est ça...


    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
    <script src="js/jquery.event.frame.js"></script>
    <script src="js/jquery.parallax.js"></script>
    <script>
      jQuery(document).ready(function(){
        jQuery('#parallax .parallax-layer')
        .parallax({
          mouseport: jQuery('#parallax')
        });
      });
      </script>


    Merci à toi!

  4. #4
    Membre averti
    Homme Profil pro
    Inscrit en
    Février 2012
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Février 2012
    Messages : 14
    Par défaut
    Bon j'ai un peu avancé du moins je pense que c'est bon...par contre je n'arrive pas à distinguer les options des variables...il faut l'ecrire comment?

    Ce que j'ai fait :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     <div class="parallax-viewport" id="parallax">
            
            <!-- parallax layers -->
            <div class="parallax-layer" style="width:298px; height:150px;">
                <img src="images/fondmenu.png" alt="" style="position:absolute; left:0px; top:-30px;"/>
            </div>
            <div class="parallax-layer" style="width:1200px; height:90px;">
                <img src="images/trainee.png" alt="" />
            </div>
            <div class="parallax-layer" style="width:1200px; height:170px;">
                <img src="images/logo3.png" alt="" style="position:absolute; top:40px; left:0px;" />
            </div>
       <div class="parallax-layer_1" style="width:1200px; height:170px;">
                <img src="images/logo3.png" alt="" style="position:absolute; top:10px; left:20px;" />
            </div>
            </div>
    et

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
    <script src="js/jquery.event.frame.js"></script>
    <script src="js/jquery.parallax.js"></script>
    <script>
      jQuery(document).ready(function(){
        jQuery('#parallax .parallax-layer')
        .parallax({
          mouseport: jQuery('#parallax')});
        jQuery('#parallax .parallax-layer_1')
        .parallax({
          mouseport: jQuery('#parallax')});
    })
      </script>
    Par contre je ne sais comment distinguer les deux en leur appliquant des options différentes...dans ce code Jquery dans le fichier jquery.parallax.js
    Me suis je bien fait comprendre? Comment donner des variables différents pour le parallax-layer_1 ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    // jquery.jparallax.js
    // 1.0
    // Stephen Band
    //
    // Project and documentation site:
    // webdev.stephband.info/jparallax/
    //
    // Repository:
    // github.com/stephband/jparallax
    //
    // Dependencies:
    // jquery.event.frame
    // webdev.stephband.info/events/frame/
     
    (function(jQuery, undefined) {
     
    	// Plugin name
    	var plugin = "parallax";
     
    	// VAR
     
    	var options = {
    	    	mouseport:	'body',    // jQuery object or selector of DOM node to use as mouse detector
    	    	xparallax:	true,      // boolean | 0-1 | 'npx' | 'n%' - Sets axis of reaction and by how much they react
    	    	yparallax:	true,      //
    	    	xorigin:		0.5,       // 0-1 - Sets default alignment. Only has effect when parallax values are something other than 1 (or true, or '100%')
    	    	yorigin:		0.5,       //
    	    	decay:			0.66,      // 0-1 (0 instant, 1 forever) - Sets rate of decay curve for catching up with target mouse position
    	    	frameDuration:	30,    // Int (milliseconds)
    	    	freezeClass:	'freeze' // String - Class added to layer when frozen
    	    },
     
    	    value = {
    	    	left: 0,
    	    	top: 0,
    	    	middle: 0.5,
    	    	center: 0.5,
    	    	right: 1,
    	    	bottom: 1
    	    },
     
    	    regex = {
    	    	px:			/^\d+\s?px$/,
    	    	percent:	/^\d+\s?%$/
    	    },
     
    	    frameEvent = 'frame.'+plugin,
     
    	    abs = Math.abs,
     
    	    pointer = [0, 0];
     
     
     
     
    	// FUNCTIONS
     
    	function parseValue(value) { return this.lib[value]; }
    	parseValue.lib = value;
     
    	// Converts numbers or numbers in strings to boolean
    	function parseBool(x) {
    		return typeof x === "boolean" ? x : !!( parseFloat(x) ) ;
    	}
     
    	function parseCoord(x) {
    		return (regex.percent.exec(x)) ? parseFloat(x)/100 : x;
    	}
     
    	// CONSTRUCTORS
     
    	function Mouse(xparallax, yparallax, decay, pointer){
     
    		// Convert parallax options to boolean values
    		var parallax = [xparallax, yparallax];
     
    		this.ontarget = false;
    		this.decay = decay;
    		this.pointer = pointer || [0.5, 0.5];
    		this.update = function(pointer, threshold){
    			var lagPointer, x;
     
    			// Pointer is already on target
    			if (this.ontarget) {
    				this.pointer = pointer;
    			}
     
    			// Pointer has arrived within the target thresholds
    			else if ((!parallax[0] || abs(pointer[0] - this.pointer[0]) < threshold[0]) &&
    			        (!parallax[1] || abs(pointer[1] - this.pointer[1]) < threshold[1])) {
    				this.ontarget = true;
    				this.pointer = pointer;
    			}
     
    			// Pointer is nowhere near the target
    			else {
    				lagPointer = [];
    				x = 2;
     
    				while (x--) {
    					if ( parallax[x] ) {
    						lagPointer[x] = pointer[x] + this.decay * (this.pointer[x] - pointer[x]);
    					}
    				}
     
    				this.pointer = lagPointer;
    			}
    		};
    	}
     
    	function Port(object, options){
    		var self = this,
    			elem = object instanceof jQuery ? object : jQuery(object) ,
    			// Convert parallax options to boolean values
    			parallax = [parseBool(options.xparallax), parseBool(options.yparallax)],
    			// State of mouse position (0 - outside, 1 - inside, 2 - just gone outside)
    			inside = 0,
    			// Stores mouse position on mouseleave event
    			leaveCoords;
     
    		this.pointer = [0, 0];
    		this.active = false;
    		this.activeOutside = (options && options.activeOutside) || false;
    		this.update = function(coords){
    			var pos = this.pos,
    				size = this.size,
    				pointer = [],
    				x = 2;
     
    			// Is mouse inside port?
    			// Yes.
    			if ( inside > 0 ) {
    				// But it just went outside, so make this the last move
    				// Use leaveCoords stored by mouseleave event
    				if ( inside === 2 ) {
    					inside = 0;
    					if (leaveCoords) {
    						coords = leaveCoords
    					};
    				}
     
    				while (x--) {
    					if ( parallax[x] ) {
    						pointer[x] = (coords[x] - pos[x]) / size[x] ;
    						pointer[x] = pointer[x] < 0 ? 0 : pointer[x] > 1 ? 1 : pointer[x] ;
    					}
    				}
     
    				this.active = true;
    				this.pointer = pointer;
    			}
    			// No.
    			else {
    				this.active = false;
    			}
    		};
    		this.updateSize = function(){
    			var width = elem.width(),
    				height = elem.height();
     
    			self.size = [width, height];
    			self.threshold = [ 1/width, 1/height ];
    		};
    		this.updatePos = function(){
    			var offset = elem.offset() || {left: 0, top: 0},
    				left = parseInt(elem.css('borderLeftWidth')) + parseInt(elem.css('paddingLeft')),
    				top = parseInt(elem.css('borderTopWidth')) + parseInt(elem.css('paddingTop'));
     
    			self.pos = [offset.left + left, offset.top + top];
    		};
     
    		// Update mouseport dimensions on window resize
    		jQuery(window)
    		.bind('resize.'+plugin, self.updateSize)
    		.bind('resize.'+plugin, self.updatePos);
     
    		// Detect entry and exit of mouse
    		elem
    		.bind('mouseenter.'+plugin, function(e){
    			inside = 1;
    		})
    		.bind('mouseleave.'+plugin, function(e){
    			inside = 2;
    			leaveCoords = [e.pageX, e.pageY];
    		});
     
    		// Set up layer
    		this.updateSize();
    		this.updatePos();
    	}
     
    	function Layer(elem, options){
    		var px = [],
    		    parallax = [],
    		    offset = [],
    		    position = [];
     
    		this.update = function(pointer){
    			var pos = [],
    			    cssPosition,
    			    cssMargin,
    			    x = 2,
    			    css = {};
     
    			while (x--) {
    				if ( parallax[x] ) {
    					pos[x] = parallax[x] * pointer[x] + offset[x];
     
    					// We're working in pixels
    					if ( px[x] ) {
    						cssPosition = position[x];
    						cssMargin = pos[x] * -1;
    					}
    					// We're working by ratio
    					else {
    						cssPosition = pos[x] * 100 + '%';
    						cssMargin = pos[x] * this.size[x] * -1;
    					}
     
    					// Fill in css object
    					if ( x === 0 ) {
    						css.left = cssPosition;
    						css.marginLeft = cssMargin;
    					}
    					else {
    						css.top = cssPosition;
    						css.marginTop = cssMargin;
    					}
    				}
    			}
     
    			// Set css
    			elem.css(css);
    		};
     
    		this.setParallax = function(xp, yp, xo, yo){
    			var p = [ xp || options.xparallax, yp || options.yparallax ],
    			    origin = [ xo || options.xorigin, yo || options.yorigin ],
    			    i = 2,
    			    css = {};
     
    			while (i--) {
    				// Set px flag
    				px[i] = regex.px.test(p[i]);
     
    				// Convert origin to numbers
    				if (typeof origin[i] === 'string') {
    					origin[i] = origin[i] === undefined ? 1 :
    								value[ origin[i] ] || parseCoord(origin[i]) ;
    				}
     
    				// We're dealing with pixel dimensions
    				if ( px[i] ) {
    					// Set parallax
    					parallax[i] = parseInt(p[i]);
     
    					// Set offset
    					offset[i] = origin[i] * ( this.size[i] - parallax[i] );
     
    					// Set css position constant
    					position[i] = origin[i] * 100 + '%';
    				}
     
    				// We're dealing with ratios
    				else {
    					// Set parallax, converting to ratio where necessary
    					parallax[i] = p[i] === true ? 1 : parseCoord(p[i]);
     
    					// Set offset
    					offset[i] = parallax[i] ? origin[i] * ( 1 - parallax[i] ) : 0 ;
    				}
    			}
    		};
     
    		this.getPointer = function(){
    			var viewport = elem.offsetParent(),
    				pos = elem.position(),
    				position = [],
    				pointer = [],
    				i = 2;
     
    			// Reverse calculate ratio from layer's current position
    			while (i--) {
    				if ( px[i] ) {
    					// TODO: reverse calculation for pixel case
    					position[i] = 0;
    				}
    				else {
    					position[i] = pos[ i === 0 ? 'left' : 'top' ] / (viewport[ i === 0 ? 'outerWidth' : 'outerHeight' ]() - this.size[i]) ;
    				}
     
    				pointer[i] = (position[i] - offset[i]) / parallax[i] ;
    			}
     
    			return pointer;
    		};
     
    		this.setSize = function(x, y){
    			this.size = [ x || elem.outerWidth(), y || elem.outerHeight() ];
    		};
     
    		this.setSize(options.width, options.height);
    		this.setParallax(options.xparallax, options.yparallax, options.xorigin, options.yorigin);
    	}
     
    	// EVENT HANDLERS
     
    	function update(e){
     
    		var elem = jQuery(this),
    		    global = e.data.global || e.data,
    		    local = e.data.local || elem.data(plugin),
    		    port = global.port,
    		    mouse = global.mouse,
    		    localmouse = local.mouse,
    		    process = global.timeStamp !== e.timeStamp;
     
    		// Global objects have yet to be processed for this frame
    		if ( process ) {
    			// Set timeStamp to current time
    			global.timeStamp = e.timeStamp;
     
    			// Process mouseport
    			port.update(pointer);
     
    			// Process mouse
    			if ( port.active || !mouse.ontarget ) {
    				mouse.update(port.pointer, port.threshold);
    			}
    		}
     
    		// Layer has it's own mouse
    		if ( localmouse ) {
     
    			// Process mouse
    			localmouse.update( local.freeze ? local.freeze.pointer : port.pointer, port.threshold );
     
    			// If it hits target
    			if ( localmouse.ontarget ) {
     
    				delete local.mouse;
     
    				// Stop animating frozen layers
    				if (local.freeze) {
    					elem
    					.unbind(frameEvent)
    					.addClass(global.freezeClass);
    				}
    			}
     
    			// Use localmouse in place of mouse
    			mouse = localmouse;
    		}
    		// Layer is responding to global mouse
    		else {
    			// When no longer active, unbind
    			if ( mouse.ontarget && !port.active ) {
    				elem.unbind(frameEvent);
    			}
    		}
     
    		local.layer.update(mouse.pointer);
    	}
     
    	jQuery.fn[plugin] = function(o){
    		var global = jQuery.extend({}, jQuery.fn[plugin].options, o),
    			args = arguments,
    			layers = this,
    			optionsArray = [];
     
    		if (undefined === jQuery.event.special.frame) {
    			throw "jquery.parallax requires jquery.event.frame.";
    		}
     
    		// Turn mouseport into jQuery obj
    		if ( !(global.mouseport instanceof jQuery) ) {
    			global.mouseport = jQuery(global.mouseport); 
    		}
     
    		global.port = new Port(global.mouseport, global);
    		global.mouse = new Mouse(parseBool(global.xparallax), parseBool(global.yparallax), global.decay);
     
    		global.mouseport
    		.bind("mouseenter", function(e){
    			var i = layers.length,
    			    layer;
     
    			global.mouse.ontarget = false;
     
    			// Animate unfrozen layers
    			while (i--) {
    				layer = layers[i];
     
    				if (!jQuery.data(layer, plugin).freeze) {
    					jQuery.event.add(this, frameEvent, update, {
    						global: global,
    						local: optionsArray[i]
    					});
    				};
    			}
    		});
     
    		return layers.each(function(i){
    			var elem = jQuery(this),
     
    			    // Construct layer options from extra arguments
    			    layerOptions = args[i+1] ? jQuery.extend({}, global, args[i+1]) : global ,
     
    			    // Set up layer data. Give it a local mouse 
    			    // initialises it to start smoothly from current position
    			    layer = new Layer(elem, layerOptions),
    			    local = {
    			    	layer: layer,
    			    	mouse: new Mouse(parseBool(layerOptions.xparallax), parseBool(layerOptions.yparallax), layerOptions.decay, layer.getPointer())
    			    };
     
    			elem.data(plugin, local);
    			optionsArray.push(local);
     
    			// Bind freeze and unfreeze actions directly to layers using
    			// jQuery.event.add(node, type, fn, data)
     
    			jQuery.event.add(this, 'freeze', function(e){
    				var elem = jQuery(this),
    				    global = e.data.global,
    				    local = e.data.local,
    				    mouse = local.mouse || local.freeze || global.mouse,
    				    coords = coords = [
    				    	e.x === undefined ? mouse.pointer[0] : parseCoord(e.x),
    				    	e.y === undefined ? mouse.pointer[1] : parseCoord(e.y)
    				    ],
    				    decay = e.decay;
     
    				// Store position
    				local.freeze = { pointer: coords };
     
    				// Create local mouse, passing in current pointer with options
    				local.mouse = new Mouse(parseBool(global.xparallax), parseBool(global.yparallax), global.decay, mouse.pointer);
     
    				if (decay !== undefined) { local.mouse.decay = decay; }
     
    				// Start animating
    				jQuery.event.add(this, frameEvent, update, global);
    			}, {
    				global: global,
    				local: local
    			});
     
    			jQuery.event.add( this, 'unfreeze', function(e){
    				var elem = jQuery(this),
    				    global = e.data.global,
    				    local = e.data.local,
    				    decay = e.decay,
    				    pointer;
     
    				if (!local.freeze) { return; }
     
    				// Create local mouse, passing local freeze pointer with options
    				pointer = local.mouse ? local.mouse.pointer : local.freeze.pointer ;
    				local.mouse = new Mouse(parseBool(global.xparallax), parseBool(global.yparallax), global);
    				local.mouse.pointer = pointer;
     
    				// Override decay with decay passed as e.decay
    				if (decay !== undefined) local.mouse.decay = decay;
     
    				// Destroy local.freeze
    				delete local.freeze;
     
    				// Remove freeze class and start animating
    				elem.removeClass(options.freezeClass);
     
    				// Start animating
    				jQuery.event.add(this, frameEvent, update, global);
    			}, {
    				global: global,
    				local: local
    			});
    		});
    	};
     
    	// EXPOSE
     
    	jQuery.fn[plugin].options = options;
     
    	// RUN
     
    	jQuery(document).ready(function(){
    		// Pick up and store mouse position on jQuery(document)
    		// IE does not register mousemove on jQuery(window)
    		jQuery(document)
    		.mousemove(function(e){
    			pointer = [e.pageX, e.pageY];
    		});
    	});
     
    }(jQuery));

    Merci d'avance pour votre aide!

  5. #5
    Rédacteur/Modérateur

    Avatar de SylvainPV
    Profil pro
    Inscrit en
    Novembre 2012
    Messages
    3 375
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2012
    Messages : 3 375
    Par défaut
    Eh bien ça ne peut pas marcher, tu n'as pas suivi la doc que tu as mis en commentaire :
    In addition to the global options above, individual layers can be passed their own set of options as extra arguments:

    jQuery('.parallax-layer')
    .parallax(options, layer_0_options, layer_1_options, ... );
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     jQuery('#parallax .parallax-layer')
        .parallax({
          mouseport: jQuery('#parallax')});
    Il faut passer les options que tu as créé à l'appel, sinon elles ne servent à rien

    Aussi si j'ai bien compris, tu n'as pas besoin d'un appel par layer. Tu dois appeler une seule fois parallax sur l'élement conteneur de tous tes layers, autrement dit #parallax

Discussions similaires

  1. Réponses: 0
    Dernier message: 16/01/2012, 10h01
  2. Réponses: 3
    Dernier message: 08/06/2010, 14h42
  3. Options dans StringGrid
    Par AnneOlga dans le forum C++Builder
    Réponses: 5
    Dernier message: 25/03/2004, 14h17

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo