如何从图像映射 href 激活 jquery 手风琴?
我已经搜索遍了,但还没有找到我的特定问题的答案。
我有一个简单的 jquery 手风琴,我希望能够从内部链接激活特定部分。该链接来自图像地图,因此观看者单击图像的某个区域,就会激活手风琴的该部分。看起来很简单,但我玩得很开心。
例如,到目前为止我有:
$(function() {
$( "#myaccordion" ).accordion({
active: false,
autoHeight: false,
navigation: true
});
});
<img src="Map.png" name="map" width="650" height="336" usemap="#hotspot" id="mymap" />
<map name="hotspot" id="hotspot">
<area shape="poly" coords="251,125,241,181,287" href="#section1" target="_self" alt="section1" />
<area shape="poly" coords="155,223,133,194,96" href="#section2" target="_self" alt="section2" />
</map>
<div id="myaccordion">
<h3><a href="#section1">Section 1</a></h3>
<div>
<p>
Section 1 content
</p>
</div>
<h3><a href="#section2">Section 2</a></h3>
<div>
<p>
Section 2 content
</p>
</div>
根据我所发现的情况,我知道这段代码与它需要的内容相去甚远,但这是我目前能弄清楚的最多的。
我能够根据其他一些线程得到的最接近的是使用 href# 激活外部链接的一个部分,但我需要在不重新加载页面的情况下实现这一点。
I've searched all over and havent quite found the answer for my particular question.
I have a simple jquery accordion and I want to be able to activate a particular section from an internal link. The link is coming from an image map so a viewer clicks on a region of the image and it activates that section of the accordion. Seems simple enough but I'm having a hell of a time with it.
So for example I have so far:
$(function() {
$( "#myaccordion" ).accordion({
active: false,
autoHeight: false,
navigation: true
});
});
<img src="Map.png" name="map" width="650" height="336" usemap="#hotspot" id="mymap" />
<map name="hotspot" id="hotspot">
<area shape="poly" coords="251,125,241,181,287" href="#section1" target="_self" alt="section1" />
<area shape="poly" coords="155,223,133,194,96" href="#section2" target="_self" alt="section2" />
</map>
<div id="myaccordion">
<h3><a href="#section1">Section 1</a></h3>
<div>
<p>
Section 1 content
</p>
</div>
<h3><a href="#section2">Section 2</a></h3>
<div>
<p>
Section 2 content
</p>
</div>
I know based on what I've been able to find that this code is a ways off from what it needs to be but this is the most I can figure out at the moment.
The closest I've been able to get based on some of the other threads is to activate a section from an external link using an href# but I need that to happen without reloading the page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过提供部分标题
id
属性,您只需对其进行click()
即可,它将激活下拉列表的该部分:在您的
区域
标签,您可以添加onclick
属性,如下所示:By giving your section headings
id
attributes, you can simplyclick()
on them and it will activate that section of the drop down:In your
area
tags, you can addonclick
attributes like so:我认为(但我不确定)我知道你想要实现什么。为什么不使用“触发器”。这将模拟一个事件。例如,如果您想在悬停 #objectB 时触发对 #objectA 的点击,您可以使用:
在您的情况下,当单击链接时,您可以模拟任何对象上的任何事件,这将导致您的手风琴执行您的操作想。
I think (but I'm not sure) that I know what you want to achieve. Why don't you use a 'trigger'. This will simulate an event. For example, if you want to trigger a click on #objectA when you hover #objectB, you'd use:
In your case, when the link is clicked, you simulate whatever event on whatever object that would cause your accordion to do what you want.
从形状调用 JavaScript:
Call JavaScript from the shape: