【问题标题】:ImageMapper Not working due to JQUERY or HTML [closed]由于 JQUERY 或 HTML,ImageMapper 无法工作 [关闭]
【发布时间】:2012-10-13 23:18:56
【问题描述】:

我在关注这个 jsfiddle:http://jsfiddle.net/nYkAG/396/ 它运行良好。

代码如下:

<img id="beatles" src="http://www.outsharked.com/imagemapster/examples/images/beatles_basic.jpg" 
style="width:400px;height:240px;" usemap="#beatles-map">
  <map name="beatles-map">
    <area shape="rect" data-name="paul,all" coords="36,46,121,131" href="#" />
    <area shape="rect" data-name="ringo,all" coords="113,76,198,161" href="#" />
    <area shape="rect" data-name="john,all" coords="192,50,277,135" href="#" />
    <area shape="rect" data-name="george,all" coords="262,60,347,145" href="#" />
  </map>

<div id="beatles-caption" style="clear:both;border: 1px solid black; width: 400px; padding: 6px; display:none;">
 <div id="beatles-caption-header" style="font-style: italic; font-weight: bold; margin-bottom: 12px;"></div>
 <div id="beatles-caption-text"></div>
</div>​

但是,为什么这对于这个 index1.html(测试)不起作用?

http://nina-naustdal.com/index1.html

感谢您的帮助

【问题讨论】:

  • 如果您查看上面列出的 jsfiddle,当您将鼠标悬停在图像上时,&lt;area&gt; 标签允许工具提示出现在底部。但是,当在 index1.html 上重新创建这样的事件不起作用时,即使我使用的是相同的代码。
  • 小提琴包括JavaScript,你的代码没有。
  • 遇到了同样的问题,重新提问here

标签: javascript jquery html css


【解决方案1】:

查看您的页面,我没有看到 jsFiddle 附带的 JavaScript。

我看到一个名为“imagemapster”的插件,但它似乎与您的小提琴示例中的代码无关。

进一步调查确认您没有在小提琴中包含来自 JS 窗口的相关 JavaScript。

你需要添加这个脚本:

// javascript
// Set up some options objects: 'single_opts' for when a single area is selected, which will show just a border
// 'all_opts' for when all are highlighted, to use a different effect - shaded white with a white border
// 'initial_opts' for general options that apply to the whole mapster. 'initial_opts' also includes callbacks
// onMouseover and onMouseout, which are fired when an area is entered or left. We will use these to show or
// remove the captions, and also set a flag to let the other code know if we're currently in an area.
var inArea, map = $('#beatles'),
    captions = {
        paul: ["Paul McCartney - Bass Guitar and Vocals",
                                                                                            "Paul McCartney's song, Yesterday, recently voted the most popular song "
                                                                                              + "of the century by a BBC poll, was initially composed without lyrics. "
                                                                                              + "Paul used the working title 'scrambled eggs' before coming up with the final words."],
        ringo: ["Ringo Starr - Drums",
                                                                                          "Dear Prudence was written by John and Paul about Mia Farrow's sister, Prudence, "
                                                                                            + "when she wouldn't come out and play with Mia and the Beatles at a religious retreat "
                                                                                            + "in India."],
        john: ["John Lennon - Guitar and Vocals",
                                                                                          "In 1962, The Beatles won the Mersyside Newspaper's biggest band in Liverpool "
                                                                                            + "contest principally because they called in posing as different people and voted "
                                                                                            + "for themselves numerous times."],
        george: ["George Harrison - Lead Guitar and Vocals",
                                                                                         "The Beatles' last public concert was held in San Francisco's Candlestick "
                                                                                            + "Park on August 29, 1966."]
    },
    single_opts = {
        fillColor: '000000',
        fillOpacity: 0,
        stroke: true,
        strokeColor: 'ff0000',
        strokeWidth: 2
    },
    all_opts = {
        fillColor: 'ffffff',
        fillOpacity: 0.6,
        stroke: true,
        strokeWidth: 2,
        strokeColor: 'ffffff'
    },
    initial_opts = {
        mapKey: 'data-name',
        isSelectable: false,
        onMouseover: function(data) {
            inArea = true;
            $('#beatles-caption-header').text(captions[data.key][0]);
            $('#beatles-caption-text').text(captions[data.key][1]);
            $('#beatles-caption').show();
        },
        onMouseout: function(data) {
            inArea = false;
            $('#beatles-caption').hide();
        }
    };
opts = $.extend({}, all_opts, initial_opts, single_opts);


// Bind to the image 'mouseover' and 'mouseout' events to activate or deactivate ALL the areas, like the
// original demo. Check whether an area has been activated with "inArea" - IE<9 fires "onmouseover"
// again for the image when entering an area, so all areas would stay highlighted when entering
// a specific area in those browsers otherwise. It makes no difference for other browsers.
map.mapster('unbind').mapster(opts).bind('mouseover', function() {
    if (!inArea) {
        map.mapster('set_options', all_opts).mapster('set', true, 'all').mapster('set_options', single_opts);
    }
}).bind('mouseout', function() {
    if (!inArea) {
        map.mapster('set', false, 'all');
    }
});

【讨论】:

  • imagemapster 在资源页面中,目前在 index1.html 上,还有其他关于为什么会发生这种情况的建议吗?
  • 是的,您引用的 jsFiddle 中的相关 JavaScript 不在页面上。您有对插件的引用,但没有对运行它的代码的引用。 (更新答案以包含相关代码)
  • 您好,感谢您的回复。我已经将该代码再次添加到网站上。然而,什么都没有。还有其他建议吗?
猜你喜欢
  • 1970-01-01
  • 2013-04-21
  • 2017-03-26
  • 2014-06-09
  • 1970-01-01
  • 2017-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多