Problem to load the background in a layer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christophe Candas

    #1

    Problem to load the background in a layer

    Hye,

    You will find here under a script which will load a picture in a layer ,
    picture depending on the cursor position. Everything's ok until the line:
    document.getEle mentById('zoom' ).style.backgro und="url('chemi n
    image.gif')";
    which doesn't work.
    The script works (indication in the status barre) but the image is not
    loaded in the layer...
    I'm quiet sure it's a problem of url syntaxe but I can't find it ???


    <script language="JavaS cript" type="text/JavaScript">
    nom_precedent = "/images/panorama_1.gif" ;

    function position(e) {
    x = (navigator.appN ame.substring(0 ,3) == "Net") ? e.pageX :
    event.x+documen t.body.scrollLe ft;
    y = (navigator.appN ame.substring(0 ,3) == "Net") ? e.pageY :
    event.y+documen t.body.scrollTo p;

    posx = Math.ceil(x/1014*21);
    posy = Math.ceil(y/290*12)-1;

    if (posx<=1) posx=1;
    if (posx>=21) posx=21;
    if (posy<=0) posy=0;
    if (posy>=7) posy=11;

    num = posx+(posy*21);
    nom = "../../../../_images/_trainers_05012 4/images/panorama_"+num+ ".gif";

    if (nom != nom_precedent) {

    window.status = "Souris posx:"+posx+" | posy:"+posy+" | numéro:"+num+" |
    image:"+nom;

    // Netscape
    if (document.getEl ementById){
    document.getEle mentById('zoom' ).style.backgro und="url('../../../../_images/_trainers_05012 4/images/panorama_51.gif ')";
    }

    if (document.all && !document.getEl ementById){
    document.all['zoom'].style.backgrou nd="url('../../../../_images/_trainers_05012 4/images/panorama_51.gif ')";
    }

    // IE
    if (document.layer s) {
    document.layers['zoom'].style.backgrou nd="url('../../../../_images/_trainers_05012 4/images/panorama_51.gif ')";
    }

    nom_precedent = nom;
    }
    }

    if (navigator.appN ame.substring(0 ,3) == "Net")
    document.captur eEvents(Event.M OUSEMOVE);
    document.onmous emove = position;

    </SCRIPT>

    </HEAD>
    <!--C.Candas, 2004.-->

    <BODY BGCOLOR="#FFFFF F">
    <img src="../../../../_images/_trainers_05012 4/panorama_flat.j pg"
    width="1014" height="290" border="0">
    <p align="center" class="retrait" >Glissez la souris sur la zone de l'image
    que vous souhaitez agrandir ci dessous.</p>
    <div id="zoom" style="position :absolute; width:500px; height:250px;
    z-index:1; visibility: visible; left: 257px; top: 346px; background-image:
    url(../../../../_images/_trainers_05012 4/images/panorama_54.gif );
    layer-background-image:
    url(../../../../_images/_trainers_05012 4/images/panorama_54.gif ); border:
    1px none #000000;"></div>



    Thanks in advance for your help.


    Christophe


  • Richard Cornford

    #2
    Re: Problem to load the background in a layer

    Christophe Candas wrote:
    <snip>[color=blue]
    > function position(e) {[/color]
    <snip>[color=blue]
    > document.getEle mentById('zoom' ).style.backgro und="url[/color]
    <snip>[color=blue]
    > }
    >
    > if (navigator.appN ame.substring(0 ,3) == "Net")
    > document.captur eEvents(Event.M OUSEMOVE);
    > document.onmous emove = position;
    >
    > </SCRIPT>[/color]
    <snip>[color=blue]
    > <BODY BGCOLOR="#FFFFF F">[/color]
    <snip>[color=blue]
    > <div id="zoom" style="position :absolute; width:500px; ...[/color]
    <snip>

    Because you assign the - position - function as a mosemove handler
    inline, before the page body (and particularly the <DIV ID="zoom">
    element) has been parsed by the browser, if there is a mosemove event in
    the interval between the assignment of the handler and the creation of
    the DIV element in the DOM then the - document.getEle mentById('zoom' ) -
    method call will return - null -, and the rest of that expression will
    result in an exception being thrown.

    Richard.


    Comment

    Working...