jQuery图像预览可以在Ajax嵌入式图像链接上使用? [英] jquery image preview that work on ajax embedded image links?

查看:80
本文介绍了jQuery图像预览可以在Ajax嵌入式图像链接上使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那里有各种不错的jquery图像预览插件.但是,我测试过的所有工具都没有使用ajax嵌入DOM的图像链接.

there are various good jquery image preview plugins out there. however, all of the ones i've tested havent worked on image links that are embedded in the DOM with ajax.

我已经测试过使用jquery live功能,但是它不能完美运行.

i have tested use jquery live feature, but it doesnt work flawless.

$('a.preview').live('mouseover', function() {
    $(this).imgPreview({
        imgCSS: {
            //width: '200px'
        },
        preloadImages:      'true',
    });
});

我正在使用此代码: http://www.webresourcesdepot.com /jquery-image-preview-plugin-imgpreview/

问题是我必须使用jquery live,如上所见.但是有两个缺陷.

the problem is that i have to use jquery live as u see above. but there is 2 flaws.

  1. 如果我第一次在缩略图上未显示预览时将鼠标移到缩略图上,我想那是因为我尚未获取图像.因此,我必须将鼠标从图像上移开,然后再次移回图像上方,然后将其显示出来.这很烦人.

  1. if i move the mouse over the thumbnail the first time it doesnt show the preview, i guess that is because i hasnt fetched the image yet. so i have to move the mouse away from the image and back over the image again, then it'll be shown. and that is very annoying.

它不预加载图像.如果您在他们的网站上查看,他们就会像这样使用它:

it doesnt preload the images. if you check on their website they are using it like this instead:

$('a.preview').imgPreview({ preloadImages:'true', });

$('a.preview').imgPreview({ preloadImages: 'true', });

,它将在DOM完全加载后预加载所有预览.但我已经封装了功能.但是,即使我没有这样做,也无法导致我在加载DOM之后添加带有ajax的这些图像链接.

and that will preload all previews after DOM is fully loaded. but i have encapsulated the function. but even if i didnt, it cant cause i add these image links with ajax AFTER DOM is loaded.

我想知道是否有人知道一个插件可以对ajax加载的元素(预览和预加载)做同样的事情.

i wonder if someone knows about a plugin that could do same stuff on ajax-loaded elements, both preview and preload.

谢谢.

推荐答案

将其添加到鼠标悬停将无济于事,因为重点是要在将鼠标悬停在图像上之前预加载图像(以便在鼠标悬停).

adding it to the mouseover will not help, as the whole point is to preload the images before they get moused over ... (so that they are available at mouseover)..

在将新链接(来自ajax)附加到dom之后,应立即添加$('a.preview').imgPreview(...).

you should add the $('a.preview').imgPreview(...) right after you attach the new links (from ajax) to the dom ..

这篇关于jQuery图像预览可以在Ajax嵌入式图像链接上使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆