onmouseover with django / imagekit

Posted by Michael Moreno on Stack Overflow See other posts from Stack Overflow or by Michael Moreno
Published on 2010-03-23T03:59:09Z Indexed on 2010/03/23 4:01 UTC
Read the original article Hit count: 530

I'm using Imagekit. View.py includes:

def pics(request):
    p = Photo.objects.all()
    return render_to_response('Shots.html',
            {'p': p})   

The following simple code in the template will generate associated images:

{% for p in p %}
<img src = "{{ p.display.url }}">
<img src = "{{ p.thumbnail_image.url }}">    
{% endfor %}

I'm attempting to generate a series of thumbnails {{ p.thumbnail_image.url }} which, when mouseover'd, will generate the slightly larger version of the image, {{ p.display.url }} via Javascript. The following code in the template attempts to do so:

<html>
<head>
<HEAD>

<script 
language="Javascript"> 
{ image1 = new Image 
image2 = new Image 
image1.src = {{  p.thumbnail_image.url }}             
image2.src = {{ p.display.url }}
</script>
</head>
<body>

{% for p in p %}
<a href=""
onMouseOver="document.rollover.src=
image2.src  
onMouseOut="document.rollover.src=
image1.src"> 
<img src="{{ p.thumbnail_image.url }}" border=0 name="rollover"></a>
{% endfor %}
</body>
</html>

This will display the series of thumbnails, but the larger image will not display when mouseover'd. I believe it has to do with how I'm specifying the variable {{ p.display.url }}.

© Stack Overflow or respective owner

Related posts about django

Related posts about JavaScript