图像作为可拖动的输入元素?

发布于 2024-12-05 09:08:09 字数 619 浏览 0 评论 0原文

嵌入图像中的输入元素

在网络浏览器中

  • 我希望

    允许图像嵌入输入元素。

  • 允许在容器内拖动这些图像

  • 以制作这些图像具有足够的自我意识,当彼此靠近时,它们“对齐”在一起

示例:屏幕转储/视频

这里有一个屏幕转储,说明了我想要的类型: https://i.sstatic.net /j5oPj.jpg

为了更好地说明这一点,这里有一个视频(打开声音):http://www.screencast.com/ t/4BaLMzHK

我们可以这样做吗?

有哪些方法可以将图像“包裹”在 HTML/JS 中的输入元素周围?

(我不想使用:Flash;Java 或 Silverlight,但如果这是唯一的方法,我对此持开放态度)。

Input Elements embedded in Images

Within a Web Browser I want

  • to allow images to have an input element embedded within them.

  • to allow those images to be dragged around within a container

  • to make those images sufficiently self-aware that when close to each other they 'snapped' together

Examples : Screen Dump/Video

There's a screen dump here which illustrates the type of thing I'd like : https://i.sstatic.net/j5oPj.jpg .

To illustrate it better there's a video here (turn your sound on) : http://www.screencast.com/t/4BaLMzHK .

Can we do this ?

What are ways you could "wrap" an image around a input element in HTML/JS ?

(I would prefer not to use: Flash; Java or Silverlight but I'm open to that if that's the only way it can be done).

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

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

发布评论

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

评论(1

吃→可爱长大的 2024-12-12 09:08:09

好的 - 这不会是一个完整的、端到端的答案,但它应该为您提供构建块。

对于初学者来说,您不需要闪存或任何其他第三方东西。 HTML、CSS 和 Javascript 将满足您所需的一切。

好的,让我们看看“具有嵌入输入的图像”要求。您所描述的实际上只是表单输入周围元素的特定视觉样式。 HTML 有一个特定的元素用于此目的 -

。字段集是块元素,可以给定背景图像(设置您想要的图像)、宽度、高度等。

我会使用这样的东西:

<fieldset class="formModule moduleTypeA">
   <label for="controlTime">Wait</label>
   <input type="text" id="controlTime" name="controlTime" value="5"/>
   <label for="controlTime">seconds</label>
</fieldset>

每个字段集都将成为一个可拖动的“模块”。样式应该足够简单 - 类似于:

fieldset.formModule {
   display:block; /* Not sure if this is strictly required - fieldsets have some funny default styles in some browsers, so I'm just playing it safe */
   width: 200px;
   height: 180px;
   padding: 10px;
   background: transparent url(formModule.png) no-repeat center center;
}

使用附加类将允许您改变所使用的模块类型:

.moduleTypeA {
   width:250px;
   height:120px;
   background-image: url(formModuleA.png);
}

.moduleTypeB {
   width:160px;
   height:200px;
   background-image: url(formModuleB.png);
}

就我个人而言,我会尝试在没有图像的情况下完成它 - 使用标准背景颜色,加上 CSS3 边框半径、阴影和渐变效果将允许您在有能力的浏览器中获得非常漂亮的“拼图”类型的视觉样式,并且速度更快且更容易维护,因为当您想要重新调整大小时,您不需要重新创建图像。模块。您可能需要添加一些“标记”元素(只是 )标记“捕捉”点。

是的 - 这样您的 HTML 和 CSS 就基本完成了。接下来,您需要拖动和捕捉。我会在这里选择 jQueryUI。它的设置过程最简单,并且应该可以在多种浏览器中运行。

查看此演示:http://jqueryui.com/demos/draggable/#snap-to< /a>

所以,你的清单将是(按顺序)

  1. 让你的表单工作的 HTML
  2. 构建你的 CSS 以使你的视觉效果看起来正确(还不用担心图像)
  3. 安装 jQuery 和 jQuery UI 并确认它们正在工作
  4. 应用表单模块的可拖动和可捕捉行为
  5. 测试一切
  6. 调整您的视觉样式,使其美观!

我希望这有帮助!这是您尝试在此处构建的相当复杂的 UI 部分 - 希望这可以将其分解为可管理的块。祝你好运!

OK - this isn't going to be a complete, end-to-end answer, but it should give you the building blocks.

For starters, you won't need flash, or any other third party stuff. HTML, CSS and Javascript will do everything you need.

OK, let's look at the 'images with embedded inputs' requirement. What you're describing is really just a particular visual style for an element surrounding a form input. HTML has a specific element for this - the <fieldset>. Fieldsets are block elements, and can be given a background image (that sets the image you want), width, height, etc.

I'd use something like this:

<fieldset class="formModule moduleTypeA">
   <label for="controlTime">Wait</label>
   <input type="text" id="controlTime" name="controlTime" value="5"/>
   <label for="controlTime">seconds</label>
</fieldset>

Each one of those fieldsets will become a draggable 'module'. The styling should be simple enough - something like:

fieldset.formModule {
   display:block; /* Not sure if this is strictly required - fieldsets have some funny default styles in some browsers, so I'm just playing it safe */
   width: 200px;
   height: 180px;
   padding: 10px;
   background: transparent url(formModule.png) no-repeat center center;
}

Using an additional class will allow you to vary the types of modules you use:

.moduleTypeA {
   width:250px;
   height:120px;
   background-image: url(formModuleA.png);
}

.moduleTypeB {
   width:160px;
   height:200px;
   background-image: url(formModuleB.png);
}

Personally, I would try to do it without images - using standard background colors, plus CSS3 border-radius, shadows and gradient effects would allow you to get a very nice 'puzzle piece' type of visual style in capable browsers, and be much faster and easier to maintain, since you wouldn't need to re-create images when you want to re-size a module. You might need to add a little 'marker' element (just a <span class="jigsawMale"> or <span class="jigsawFemale">) to mark the 'snap' points.

Right - so that's your HTML and CSS mostly done. Next, you need dragging and snapping. I'd go for jQueryUI here. It's the least painful to set up, and should work in a good variety of browsers.

Check this demo out: http://jqueryui.com/demos/draggable/#snap-to

So, your checklist will be (in order)

  1. Get your HTML for your forms working
  2. Build up your CSS to get your visuals looking right (not worrying about images yet)
  3. Install jQuery and jQuery UI and confirm they're working
  4. Apply the draggable and snappable behaviour to your form modules
  5. Test everything
  6. Tweak your visual styles to make it beautiful!

I hope that helps! It's a fairly complex piece of UI you're trying to build here - hopefully this breaks it down into manageable chunks. Good luck!

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