4

我无法将图像映射添加到我的 nivo 滑块。下面是我正在使用的代码,这里是该站点的链接。有什么建议么?

<div class="slider-wrapper theme-default">
    <div id="slider" class="nivoSlider">
        <img src="wp-content/themes/sourcetone/images/1-difference.png" data-thumb="wp-content/themes/sourcetone/images/1-difference.png" alt="" />
        <img src="wp-content/themes/sourcetone/images/2-mood.png" data-thumb="wp-content/themes/sourcetone/images/2-mood.png" alt="" usemap="#mood" />
        <img src="wp-content/themes/sourcetone/images/3-activity.png" data-thumb="wp-content/themes/sourcetone/images/3-activity.png" alt="" usemap="#activity" />
        <img src="wp-content/themes/sourcetone/images/4-health.png" data-thumb="wp-content/themes/sourcetone/images/4-health.png" alt="" usemap="#health" />
        <img src="wp-content/themes/sourcetone/images/5-buy.png" data-thumb="wp-content/themes/sourcetone/images/5-buy.png" alt="" usemap="#buy" />
    </div>
    <map name="mood" id="mood"><area shape="rect" coords="10,453,162,482" href="/products/our-products/more-info/" alt="" /><area shape="rect" coords="10,400,162,445" href="google play" alt="" /></map>
    <map name="activity"><area shape="rect" coords="929,449,1081,478" href="/products/our-products/more-info/" alt="" /><area shape="rect" coords="929,398,1081,443" href="google play" alt="" /></map>
    <map name="health"><area shape="rect" coords="11,449,163,478" href="/products/our-products/more-info/" alt="" /><area shape="rect" coords="11,396,163,441" href="google play" alt="" /></map>
    <map name="buy"><area shape="rect" coords="563,251,790,314" href="/products/our-products/more-info/" alt="" /><area shape="rect" coords="563,333,790,375" href="google play" alt="" /></map>
</div>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/js/jquery.nivo.slider.js"></script>
<script type="text/javascript">
    $(window).load(function() {
        $('#slider').nivoSlider({
            effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
            animSpeed: 800, // Slide transition speed
            pauseTime: 5000, // How long each slide will show
            lastSlide: function(){}, // Triggers when last slide is shown
        });
    });
</script>
4

2 回答 2

2

老实说,我不认为这是可能的,因为 Nivo Slider 实际上会将您的图像分解为数十个较小的图像。

本质上,Nivo 利用了与精灵相同的技术,通过将图像加载到页面中(因此,它被缓存),然后将其用作数十个较小图像的背景,所述背景移动了所需的任何数量显示整个div图像的所需部分。因此,您实际提供给 Nivo 的图像本身永远不会显示。

因为图像映射不能直接div应用于div. 如果这不可行,我建议您直接联系 Nivo,询问他们是否有任何想法/解决方案可以直接与他们的插件集成。

如果您还有其他问题,请告诉我。祝你好运!:)

于 2013-04-12T21:41:28.860 回答
0

您可以使用 jQuery 动态更新映射

function drawMap() {
    // remove image overlays used during transition
    $('.nivo-slice, .nivo-box').remove();
    // set usemap attribute for current image
    var currentImage = $('#nivo-slider').data('nivo:vars').currentSlide;
    $('.nivo-main-image').attr("useMap", "#map-" + currentImage);
}

然后在加载后和每次转换后调用该函数

$('.nivoSlider').nivoSlider({
    // slider config
    afterLoad: drawMap,
    afterChange: drawMap
));
于 2014-01-08T04:25:01.977 回答