2

OnMouseover image I am getting from custom meta box and OnMouseout image is featured image.

Here is my code:

$image_full = wp_get_attachment_image_src(get_post_thumbnail_id($postid), 'full');
$him = $post_meta['_hover_image'];
<img onmouseover="this.src=\'' .$him[0]. '\'"
     onmouseout="this.src=\''.$image_full[0].'\'" src="'.$image_full[0].'"  />

Everything is working fine but taking time to show image.

1

1 Answer 1

2

This issue is likely caused by the delay in loading the resource. To help with this, you can cache the image at the URL by loading it in JavaScript with something like the following:

function preloadImage(url)
{
    var img=new Image();
    img.src=url;
}

preloadImage($him[0]);
preloadImage($image_full[0]);

If the images are not dynamic, you can also preload them using CSS. More info about this can be found here: CSS3 image preloading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.