使用 jquery imgAreaSelect 防止多个图像选择

发布于 2025-01-07 08:28:54 字数 984 浏览 0 评论 0原文

我正在使用流行的图像选择 jquery 插件 imgAreaSelect - http://odyniec.net/projects/imgareaselect

该页面可以包含任意数量的图像,因此我为图像分配了一个类,以在所有图像上启用代码。

$('img.select').imgAreaSelect({
...
});

问题是,一旦对任意一张图像进行了选择,我想防止对页面上的其余图像进行另一次选择。本质上,我希望禁用除我选择的图像之外的所有图像的插件。

我还希望能够在某个时候使用我保存的坐标再次编辑选择,因此这就是实例 api 的用武之地 - http://odyniec.net/projects/imgareaselect/usage.html#api-methods

因此,我会考虑做一些事情问题

var select1 = $('img.select1').imgAreaSelect({
...
});

var select2 = $('img.select2').imgAreaSelect({
...
});

etc

是没有定义数量的图像。我可以使用类似 $('img.select').each() 的东西吗?但仍然无法帮助向其附加数字。我认为设置 api 实例部分将有助于解决我的第一个问题。

我的问题是,如何使用 select 类为页面上的每个 img 动态创建一个 imgAreaSelect 实例(并且可能附加一个数字(我已将其存储在 name attr)) 并在选择图像时禁用页面上的所有其他实例?谢谢!

I'm using the popular image selection jquery plugin imgAreaSelect - http://odyniec.net/projects/imgareaselect

The page could have any number of images so I have assigned a class to the image to enable the code on all of them.

$('img.select').imgAreaSelect({
...
});

The problem is once a selection has been made on any 1 of the images I want to prevent another selection being made on the remaining images on the page. Essentially I am looking to disable the plugin for all images apart from the one I have selected.

I will also want to be able to edit the selection again at some point using the coords which i've saved, so this is where the instance api comes in - http://odyniec.net/projects/imgareaselect/usage.html#api-methods

I'll therefore be looking at doing something along the lines of

var select1 = $('img.select1').imgAreaSelect({
...
});

var select2 = $('img.select2').imgAreaSelect({
...
});

etc

The problem is a don't have a defined number of images. Could i used something like $('img.select').each()? Still doesn't help with appending a number to it though. I figure setting up the api instance part will help towards fixing my first issue.

My question is, how can I dynamically create an imgAreaSelect instance for each img on the page with a class of select (and probably with a number appended to it (which i've stored in the name attr)) and when an image is selected disable all other instances on the page? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望喜 2025-01-14 08:28:54

好的,我已经使用 .each() 来遍历每个图像并将 imgAreaSelect 的实例添加到数组中。从那里我可以调用我需要的任何图像。

var images = {};
var i = 1;
$('img.select').each(function (){
   images[i] = $('img.select.' + i).imgAreaSelect({
   ...
   });
   i++;
});

这可能不是最好或最有效的方法......但对我来说看起来很整洁。仍然愿意接受建议。

Ok so i've used .each() to go through each image and add the instance of imgAreaSelect into an array. From there i can make calls to whichever image i need.

var images = {};
var i = 1;
$('img.select').each(function (){
   images[i] = $('img.select.' + i).imgAreaSelect({
   ...
   });
   i++;
});

It may not be the best or most efficient way...looks pretty tidy to me though. Still open to suggestions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文