简体   繁体   English

带有bxSlider的jQuery qTip

[英]jQuery qTip with bxSlider

I'm trying to place annotations using qTip on images in bxSlider. 我正在尝试使用qTip在bxSlider中的图像上放置注释。 By default, qTip and bxSlider seem to work pretty well together, but I have it set up so that qTip shows by default instead of on mouseenter. 默认情况下,qTip和bxSlider似乎可以很好地协同工作,但是我对其进行了设置,以便默认情况下而不是在mouseenter上显示qTip。 When I go to the next slide, the tip for the previous slide stays in place. 当我转到下一张幻灯片时,上一张幻灯片的提示保持不变。 This is what I have right now: 这就是我现在所拥有的:

JSFiddle 的jsfiddle

bxSlider bxSlider

$(document).ready(function(){
 var slider = $('.bxslider').bxSlider({
    adaptiveHeight: true,
    swipeThreshold: 100,
    oneToOneTouch: false,
    easing: 'cubic-bezier(0.600, 0.060, 0.500, 1)',
     onSliderLoad: function(){
  },
  onSlideBefore: function($slideElement, oldIndex, newIndex) {
    $('.qtip').hide();
},
  onSlideAfter: function($slideElement){
  jQuery('video').trigger('play');
  $('.qtip').show();
  },
}).on('click', function(){
    slider.goToNextSlide();
});

  });

qTip qTip

$(document).ready(function()
{
    $('area[alt]').qtip(
    {
     hide: false,
        content: {
            attr: 'alt' // Use the ALT attribute of the area map for the content
        },
         show: {
        ready: true
        },
        style: {
            classes: 'caption'
        }
    });
});

How would I go about targeting and showing only the tips for the current slide? 如何定位并仅显示当前幻灯片的提示?

I got the tip to show on only the slide it belongs to. 我得到的提示仅在其所属的幻灯片上显示。 I think it's how your'e callbacks are being called. 我认为这是调用您的回调的方式。 There's a link in the image map that did nothing so I placed preventDefault() within your video trigger ( which does nothing at the moment.) I attempted to separate your events more evenly since there's a lot of stuff going on during a slide transition. 图像映射中有一个没有执行任何操作的链接,因此我在您的视频触发器中放置了preventDefault() (目前不执行任何操作。)由于幻灯片过渡期间发生了很多事情,因此我尝试更均匀地分离事件。 Here's the fiddle Btw there was an open figure end tag and an open li tag I commented them out. 这是小提琴,顺便说一句,有一个开放的figure结尾标签和一个开放的li标签,我已将其注释掉。 Sorry I had to change names, it helps me to think faster. 抱歉,我不得不更名,这有助于我更快地思考。 Let me know if you need more info. 让我知道您是否需要更多信息。

Update 1 更新1

I just thought of something, the qTip was popping up on the second slide and I originally thought it's a call back problem. 我只是想到了一些问题,第二个幻灯片中弹出了qTip,我最初以为是回叫问题。 Instead of the qTip not hiding it was probably stuck in that state because of those open figure and li end tags actually functioned as the end tags for both images and slides. 由于那些开放的figureli结束标签实际上充当了图像和幻灯片的结束标签,因此qTip没有隐藏而不是隐藏在该状态。 So essentially instead of 2 slides you had one big slide so as far as qTip was concerned, the cat image was part of your image map. 因此就qTip而言,基本上没有2张幻灯片,而是一张大幻灯片,猫图像是您图像映射的一部分。

Update 2 更新2

I noticed my Fiddle keeps on breaking. 我注意到我的小提琴一直在挣扎。 Upon further examination I noticed the bx external files are hosted on your domain and also all of the URLs are not HTTPS which jsFiddle doesn't like. 经过进一步检查,我发现bx外部文件托管在您的域中,并且所有URL都不是jsFiddle不喜欢的HTTPS。 I am using jsDelivr for bxSlider , CDNjs for qTip , and Microsoft for jQuery 我正在将jsDelivr用于bxSlider ,将CDNjs用于qTip ,并将Microsoft用于jQuery

HTML HTML

    <ul class="bxslider">
    <li class="slide">
        <figure>
            <img src="http://i.imgur.com/vLRGSyz.png" usemap="#savage">
            <map id="savage" name="savage">
                <area shape="circle" alt="Adam Savage" title="Savage Twins" coords="330,131,32" href="#" target="_self" />
            </map>
        </figure>
    </li>
    <li class="slide">
        <figure>
            <img src="http://i.imgur.com/wQAnzvl.jpg" alt="cat" title="feline">
        </figure>
    </li>
    <!-- </figure>
   </li>-->
</ul>

jQuery jQuery的

$(document).ready(function () {
    var bx = $('.bxslider').bxSlider({
        adaptiveHeight: true,
        swipeThreshold: 100,
        oneToOneTouch: false,
        easing: 'cubic-bezier(0.600, 0.060, 0.500, 1)',
        /*     onSliderLoad: function(){},*/
        onSlideBefore: function ($ele, from, to) {
            $('.qtip').hide();
        },
        onSlideAfter: function ($ele) {
            jQuery('video').on('play', function (eve) {
                eve.preventDefault();
                $('.qtip').show();
                this.on('click', function () {
                    var that = this;
                    bx.goToNextSlide(this, that[from], to);
                });
            });
        }
    });

});


$(document).ready(function () {
    $('area[alt]').qtip({
        hide: false,
        content: {
            attr: 'alt' // Use the ALT attribute of the area map for the content
        },
        show: {
            ready: true
        },
        style: {
            classes: 'caption'
        }
    });
});

Update 3 更新3

Untested 未经测试

/* Use: $(document).on('click', this, event handler); 
/* instead of $(this).click(event handler);
/* Create an .ON event handler */
$(document).on('click', '.area', function(event) {
    $(this).qtip({                // Bind qTip inside the .ON event handler
            overwrite: false,     // prevents qTip from being overridden
            content: $('.area'),  // area.area as content element
                 attr: 'alt',     // area.area[alt] as content
                 show: {          // SHOW qTip event when...
                    ready: true, /* ...when qTip is loaded, and READY */
                    event: event.type /*...when the EVENT (which is 'click') happens to THIS(which is .area) */
                 },
            },event); /* Pass the live event to qTip */
});

Details: http://qtip2.com/guides#integration 详细信息: http : //qtip2.com/guides#integration

PS Assign the area element .area PS分配area元素.area

Example

<area **class="area"** shape="circle" alt="Adam Savage" title="Savage Twins" coords="330,131,32" href="#" target="_self" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM