What's the best way to display an exploded image using minimal JQuery?
Goal:
- On hover (or: hover), enlarge the preview image by about 400% and display it in the center of the page.
- Remove preview when mouse leaves
Problem:
- Solutions like FancyBox are too bloated
- in the case of FancyBox, it ignores the width and height of the image elements, making it useless.
- Most of these "lightboxes" steal focus when called
Indeed, I'm just looking for a simple, effective solution.
+2
a source to share
2 answers
try something like this. the trick is position
you can put the div wherever you want. read something here . and you can read about hover here
Here's an example html. (copy this to a text file and open it with your browser)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Test</title>
<script text="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js">
</script>
</head>
<body>
<ul>
<li class="">Lynx</li>
<li>Jaguar</li>
</ul>
<div id="picture" style="position:absolute; top:0px; right:0px;">
</div>
<script type="text/javascript">
var animal = {
"Lynx":
"http://wnbaoutsiders.files.wordpress.com/2009/06/lynx21.jpg",
"Jaguar" :
"http://www.tropical-rainforest-animals.com/image-files/jaguar.jpg"
}
var hovered = function(e) {
//you can get what to show from the elemnt, instead of the content
// you could use an id.
var name = $(e.target).html()
$('#picture').append("<img src='" + animal[name] +"'/>")
}
var unhovered = function() {
$('#picture').empty();
}
//here you bind mouseenter and mouseleave
$('li').hover(hovered, unhovered);
</script>
</body>
0
a source to share