/    Sign up×
Community /Pin to ProfileBookmark

image swap from different div

Hi all,

I have searched and searched but not finding an answer to this one – I am hoping someone here can point me in the right direction!

I want to be able to hover over an image and for the image in a DIFFERENT div to change. (Think ecommerce site – hover over a thumbnail and the big, main image of the product becomes that thumbnail).

So – let me say that again as it’s a little hard to describe.

I have a small image and a big image. The images are in different divs. When the user hovers over the small image, the big image changes.

I don’t think this is possible in pure CSS, so I am guessing it needs some javascript.

Any ideas/pointers/suggestions please?!

Many thanks!

Rob.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@nap0leonFeb 21.2012 — Here is a non-elegant way of doing it.

<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;script language="JavaScript" type="text/javascript"&gt;
function swap(e){
thisimage = e.src;
document.getElementById('bigImage').src = thisimage;

}

&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="list"&gt;
&lt;img src="1.jpg" height="10" width="10" onmouseover="swap(this);"/&gt;&lt;br/&gt;
&lt;img src="2.jpg" height="10" width="10" onmouseover="swap(this);"/&gt;&lt;br/&gt;
&lt;img src="3.jpg" height="10" width="10" onmouseover="swap(this);"/&gt;&lt;br/&gt;
&lt;img src="4.jpg" height="10" width="10" onmouseover="swap(this);"/&gt;&lt;br/&gt;
&lt;/div&gt;
&lt;div id="main"&gt;
&lt;img id="bigImage" src="1.jpg" height="100" width="100"/&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;


Presumably, rather than just shrinking down a full sized image into a thumbnail, your thumbnail images would be named like "1_thumb.jpg" and your big image would be named like "1.jpg" - in the swap(e) function, you would want to remove the "_thumb" from 'thisimage' before updating the big image.
×

Success!

Help @nightster spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...