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 :

Paralax: paramètre adjuster


Sujet :

jQuery

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    75
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 75
    Points : 22
    Points
    22
    Par défaut Paralax: paramètre adjuster
    Bonjour,

    j'ai utilisé le tutorial suivant pour faire un site avec un effet paralax jquery:
    Cela fonctionne pas mal, mais il n'est pas tjs très ajusté car j'ai parfois un espace entre 2 images de fond si je redimensionne le navigateur.

    http://www.ianlunn.co.uk/blog/code-t...orld-parallax/

    Le point que je n'ai pas compris est le paramètre adjuster (ici 900 dans cet exemple):
    je n'arrive pas a comprendre comment il est calculé dans l'exemple par rapport à la taille des images de fond ou des div.
    Si quelqu'un a déjà utilisé cela ou a eu ce problème, merci:


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    if($firstBG.hasClass("inview")){
        $firstBG.css({'backgroundPosition': newPos(50, windowHeight, pos, 900, 0.3)});
    }

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    	//function that is called for every pixel the user scrolls. Determines the position of the background
    	/*arguments: 
    		x = horizontal position of background
    		windowHeight = height of the viewport
    		pos = position of the scrollbar
    		adjuster = adjust the position of the background
    		inertia = how fast the background moves in relation to scrolling
    	*/
    	function newPos(x, windowHeight, pos, adjuster, inertia){
    		return x + "% " + (-((windowHeight + pos) - adjuster) * inertia)  + "px";
    	}

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2007
    Messages
    75
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2007
    Messages : 75
    Points : 22
    Points
    22
    Par défaut
    Par exemple le taille de son premier bg est de 600
    Celle de son second est de 1300

    Code css : 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
    #header{
    	background: white;
    	height: 130px;	
    }
     
    #intro{
    	background:url(images/firstBG.jpg) 50% 0 no-repeat fixed;
    	color: white;
    	height: 600px;
    	margin: 0;
    	padding: 160px 0 0 0;
    }
     
    #second{
    	background: url(images/secondBG.jpg) 50% 0 no-repeat fixed;
    	color: white;
    	height: 1300px;
    	margin: 0 auto;
    	overflow: hidden;
    	padding: 0;
    }
     
     
    #second .bg{
    	background: url(images/trainers.png) 50% 0 no-repeat fixed;
    	height: 1000px;
    	margin: 0 auto;
    	padding: 0;
    	position: absolute;
    	width: 900px;
    	z-index: 200;
    }
     
    #third{
    	background: url(images/thirdBG.jpg) 50% 0 no-repeat fixed;
    	color: white;
    	height: 650px;
    	padding: 100px 0 0 0;	
    }
     
    #fourth{
    	background: url(images/bubbles2.png), url(images/bubbles2.png), url(images/bubbles1.png), url(images/fourthBG.jpg);
    	background-position: 50% 0, 50% 0, 50% 0, 50% 0;
    	background-color: #036;
    	background-attachment: fixed;
    	background-repeat: repeat, repeat, repeat ,no-repeat;
    	color: white;
    	height: 1300px;
    	padding: 100px 0 0 0;
    }
     
    #fifth{
    	background: #ccc;
    	height: 1000px;
    	margin: 0 auto;
    	padding: 40px 0 0 0;
    }
     
    .story{
    	margin: 0 auto;
    	min-width: 980px;
    	width: 980px;
    }
     
    .story .float-left, .story .float-right{
    	padding: 100px 0 0 0;
    	position: relative;
    	width: 350px;	
    }

    et je ne comprends pas les valeurs choisies pour le paramètre adjuster:
    900 pour le premier: newPos(50, windowHeight, pos, 900, 0.3)...

    Code javascript : 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
     
    //function to be called whenever the window is scrolled or resized
    	function Move(){ 
    		var pos = $window.scrollTop(); //position of the scrollbar
     
    		//if the first section is in view...
    		if($firstBG.hasClass("inview")){
    			//call the newPos function and change the background position
    			$firstBG.css({'backgroundPosition': newPos(50, windowHeight, pos, 900, 0.3)}); 
    		}
     
    		//if the second section is in view...
    		if($secondBG.hasClass("inview")){
    			//call the newPos function and change the background position
    			$secondBG.css({'backgroundPosition': newPos(50, windowHeight, pos, 1250, 0.3)});
    			//call the newPos function and change the secnond background position
    			trainers.css({'backgroundPosition': newPos(50, windowHeight, pos, 1900, 0.6)});
    		}
     
    		//if the third section is in view...
    		if($thirdBG.hasClass("inview")){
    			//call the newPos function and change the background position
    			$thirdBG.css({'backgroundPosition': newPos(50, windowHeight, pos, 2850, 0.3)});
    		}
     
    		//if the fourth section is in view...
    		if($fourthBG.hasClass("inview")){
    			//call the newPos function and change the background position for CSS3 multiple backgrounds
    			$fourthBG.css({'backgroundPosition': newPos(0, windowHeight, pos, 200, 0.9) + ", " + newPos(50, windowHeight, pos, 0, 0.7) + ", " + newPos(50, windowHeight, pos, 0, 0.5) + ", " + newPos(50, windowHeight, pos, 700, 0.3)});
    		}
     
    		$('#pixels').html(pos); //display the number of pixels scrolled at the bottom of the page
    	}

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. créer un noeuds avec des paramétres
    Par Toxine77 dans le forum XMLRAD
    Réponses: 5
    Dernier message: 21/01/2003, 16h11
  2. [xmlrad] Pb de paramètre ?
    Par Pm dans le forum XMLRAD
    Réponses: 7
    Dernier message: 07/01/2003, 14h37
  3. [SWT] Problème de paramètre GridData
    Par yolepro dans le forum SWT/JFace
    Réponses: 4
    Dernier message: 06/12/2002, 10h37
  4. passage en paramètre d'un array dynamique 2D
    Par Guigui_ dans le forum Langage
    Réponses: 4
    Dernier message: 27/11/2002, 19h47
  5. Paramètre requete SQL (ADOQuery)
    Par GaL dans le forum C++Builder
    Réponses: 3
    Dernier message: 30/07/2002, 11h24

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