适用于ajax嵌入式图像链接的jquery图像预览?

2023-09-05前端开发问题
1

本文介绍了适用于ajax嵌入式图像链接的jquery图像预览?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

那里有各种优秀的 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.但有两个缺陷.

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: '真',});

$('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 ..

这篇关于适用于ajax嵌入式图像链接的jquery图像预览?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

ajax请求获取json数据并处理的实例代码
ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc...
2024-11-22 前端开发问题
215

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 单选框、复选框、下拉菜单不显示问题如何解决?
1. 如果是ajax嵌套了 页面, 请确保 只有最外层的页面引入了layui.css 和 layui.js ,内层页面 切记不要再次引入 2. 具体代码如下 layui.use(['form', 'upload'], function(){ var form = layui.form; form.render(); // 加入这一句});...
2024-11-09 前端开发问题
313

layui中表单会自动刷新的问题
layui中表单会自动刷新的问题,因为用到layui的表单,遇到了刷新的问题所以记录一下: script layui.use(['jquery','form','layer'], function(){ var $ = layui.jquery, layer=layui.layer, form = layui.form; form.on('submit(tijiao)', function(data){ a...
2024-10-23 前端开发问题
262

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125