jQuery 图像交换
例如,我有 3 个色域。
- 颜色
- 完成突出
- 显示
现在,当用户单击“颜色”时,图像会根据颜色发生变化。当用户单击“完成”时,饰面会发生变化,并且颜色选择保持为他们选择的......等等。
我正在尝试用 jQuery 来完成这个任务。我正在考虑对产品进行命名约定......类似于“Product_Color_Finish_Highlights.jpg”的内容,然后我将结合所做的选择来更改文件名的适当“部分”。然后将新文件名作为“target_image”的“src”发送。
我已经编写了一些内容,例如手风琴菜单和其他简单的内容,但没有任何内容需要更改图像的源。我已经读了几天了,只是无法想出一个好的起点,或者为此制定“攻击计划”。
我不认为我需要太多关于实际 jQuery 的帮助,但只是......从哪里开始? 我该如何攻击这个?
I have 3 color fields... for example.
- Color
- Finish
- Highlights
Now when a user clicks the "Color" the image changes according to the color. When the user clicks "Finish" the finish changes, and the Color selection stays as they have chosen.. and so on.
I am trying to accomplish this in jQuery. I'm thinking of having a naming convention with the products.. something along the lines of "Product_Color_Finish_Highlights.jpg" then I would change the appropriate 'piece' of the filename in conjunction with the selection made. Then send the new filename as the 'src' of the 'target_image'
I have written a few things like accordion menus, and other simple things, but nothing where I would need to change the source of the image. I have been reading now for a couple days, and just unable to wrap my head around a good starting point, or 'plan of attack' for this.
I don't think I need to much help with the actual jQuery, but just rather.. where to begin?
How do I attack this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从这个开始:
或者,澄清一下您的需要,您将获得更具体的帮助。
进入猜测模式。你暗示了一些更基于惯例的东西。假设您有以下标记,可能是由脚本生成的:
您可以使用以下内容驱动
img
src
标记:这不需要任何特定的类或 ID - - 只是
select
位于img
旁边,并且img
文件名包含选择器中的值。那是什么?您不希望您的图像与选择器相邻? OK,然后,将两者通过 picker-id
whatever
的 id 约定和whatever--swatch
的相关 image-id 链接在一起。然后这段代码将起作用:这应该使用该约定来查找图像并更新其
src
。这些代码示例都没有经过测试,但它们应该会激发一些可行的东西。
Start with this:
Or, clarify a bit what you need and you'll get more specific help.
Entering guess mode. You hinted at something more conventions based. Suppose you had the following markup, possibly generated by a script:
You could drive the
img
src
tags with this:That doesn't require any specific classes or IDs on anything--just that the
select
s be next to theimg
s and that theimg
filename include the value from the picker.What's that? You don't want your images adjacent to the pickers? OK then, link the two together with the id convention of picker-id
whatever
and related image-id ofwhatever--swatch
. Then this code will work:This should use that convention to find the image and update its
src
.None of these code samples has been tested but they should inspire something that works.