JSFiddle - React, Tailwind, and code Playground

by thewebmaster

HTML

<body>
<h1>Test load multiple images on hover</h1>
<ul class="hoverbox">
<li>
<a href="#"><img src="http://www.cheap-web.nl/images/stories/virtuemart/category/Joomlart_premium_511416a84cb4b.jpg" alt="description" /><img src="http://www.cheap-web.nl/images/stories/virtuemart/category/Joomlart_premium_511416a84cb4b.jpg" alt="description" class="preview" /></a>
</li>
<li>
<a href="#"><img src="http://www.cheap-web.nl/images/stories/virtuemart/category/JoomlaXTC_design_51140e88f23dd.jpg" alt="description" /><img src="http://www.cheap-web.nl/images/stories/virtuemart/category/JoomlaXTC_design_51140e88f23dd.jpg" alt="description" class="preview" /></a>
</li>
<li>
<a href="#"><img src="http://www.cheap-web.nl/images/stories/virtuemart/category/abstract_large.jpg" alt="description" /><img src="http://www.cheap-web.nl/images/stories/virtuemart/category/abstract_large.jpg" alt="description" class="preview" /></a>
</li>
<li>
<a href="#"><img src="http://www.cheap-web.nl/images/stories/virtuemart/category/Designs___ontwer_4c7f8f86c745f.jpg" alt="description" /><img src="http://www.cheap-web.nl/images/stories/virtuemart/category/Designs___ontwer_4c7f8f86c745f.jpg" alt="description" class="preview" /></a>
</li>
<li>
<a href="#"><img src="img/photo05.jpg" alt="description" /><img src="img/photo05.jpg" alt="description" class="preview" /></a>
</li>
<li>
<a href="#"><img src="img/photo06.jpg" alt="description" /><img src="img/photo06.jpg" alt="description" class="preview" /></a>
</li>
<li>
<a href="#"><img src="img/photo07.jpg" alt="description" /><img src="img/photo07.jpg" alt="description" class="preview" /></a>
</li>
<li>
<a href="#"><img src="img/photo08.jpg" alt="description" /><img src="img/photo08.jpg" alt="description" class="preview" /></a>
</li>
<li>
<a href="#"><img src="img/photo09.jpg" alt="description" /><img src="img/photo09.jpg" alt="description" class="preview" /></a>
</li>
<li>
<a href="#"><img src="img/photo10.jpg" alt="description" /><img src="img/photo10.jpg"...

CSS

*
{
	border: 0;
	margin: 0;
	padding: 0;
}

/* =Basic HTML, Non-essential
----------------------------------------------------------------------*/

a
{
	text-decoration: none;
}

body
{
	background: #fff;
	color: #777;
	margin: 0 auto;
	padding: 50px;
	position: relative;
	width: 620px;
}

h1
{
	background: inherit;
	border-bottom: 1px dashed #ccc;
	color: #933;
	font: 17px Georgia, serif;
	margin: 0 0 10px;
	padding: 0 0 5px;
	text-align: center;
}

p
{
	clear: both;
	font: 10px Verdana, sans-serif;
	padding: 10px 0;
	text-align: center;
}

p a
{
	background: inherit;
	color: #777;
}

p a:hover
{
	background: inherit;
	color: #000;
}

/* =Hoverbox Code
----------------------------------------------------------------------*/

.hoverbox
{
	cursor: default;
	list-style: none;
}

.hoverbox a
{
	cursor: default;
}

.hoverbox a .preview
{
	display: none;
}

.hoverbox a:hover .preview
{
	display: block;
	position: absolute;
	top: -33px;
	left: -45px;
	z-index: 1;
}

.hoverbox img
{
	background: #fff;
	border-color: #aaa #ccc #ddd #bbb;
	border-style: solid;
	border-width: 1px;
	color: inherit;
	padding: 2px;
	vertical-align: top;
	width: 100px;
	height: 75px;
}

.hoverbox li
{
	background: #eee;
	border-color: #ddd #bbb #aaa #ccc;
	border-style: solid;
	border-width: 1px;
	color: inherit;
	display: inline;
	float: left;
	margin: 3px;
	padding: 5px;
	position: relative;
}

.hoverbox .preview
{
	border-color: #000;
	width: 200px;
	height: 150px;
}

JavaScript

var image = document.getElementById('initialSequence');
image.images = ['http://www.cheap-web.nl/images/stories/virtuemart/category/Joomlart_premium_511416a84cb4b.jpg', 'http://www.cheap-web.nl/images/stories/virtuemart/category/JoomlaXTC_design_51140e88f23dd.jpg', '3.jpg', '4.jpg', '5.jpg'];
image.counter = 0;
 
image.onmouseover = function () {
    this.counter += 1;
    this.src = this.images[this.counter];
}

function preload(images) {
    var image = [],
        i;
    for (i = 0; i < images.length; i += 1) {
        image[i] = new Image();
        image[i].src = images[i];
    }
}
preload([
    'http://www.cheap-web.nl/images/stories/virtuemart/category/Joomlart_premium_511416a84cb4b.jpg',
    'http://www.cheap-web.nl/images/stories/virtuemart/category/JoomlaXTC_design_51140e88f23dd.jpg',
    'http://www.cheap-web.nl/images/stories/virtuemart/category/abstract_large.jpg'
]);