JQuery 循环 - 淡入/淡出中断

发布于 2024-12-09 10:27:10 字数 2869 浏览 0 评论 0原文

我有一个 JQuery 幻灯片,其中一些文本/幻灯片淡入淡出。

同时我有一个导航/点击点。当您单击某个位置时,幻灯片/文本会发生变化。

问题是当文本/幻灯片淡入淡出并且用户单击某个位置时,淡入淡出会中断。如果用户快速单击所有点,则会同时显示来自不同幻灯片的文本。

我希望淡出结束,然后用户可以单击。简而言之:当淡入淡出时没有点击。

我做了一个小例子来说明这个问题。

html 的头部部分:

<style type="text/css">
     .slideshow
     {
         width:600px;
         height:30px;
         background-color:#0FF;                      
         overflow:hidden;
         margin:50px;
     }
     .slideshow_text_font
     {
         font:Verdana, Geneva, sans-serif;
         font-size:22px;
         font-weight:bold;       
     }
  </style>

  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script type="text/javascript" src="js/jquery.cycle.all.latest.js"></script>

  <script type="text/javascript"> 
     $(document).ready(function() {
         $('.slideshow').cycle({                        
            fx: 'custom',
             sync: 0,
             cssBefore: {
                 opacity:0,
                 display: 'block'
             },
             animIn:  {
                 opacity:1               
             },
             animOut: {
                 opacity:0
             },
             timeout:5000,
             speed:2000
         });
     });

     if (document.images) {
         function setSlide(index) { 
           $('.slideshow').cycle(index);
         } 
     }
   </script>

html 的主体部分:

<div class="slideshow">
    <div><a class="slideshow_text_font">1. Some text for slide number one</a></div>
    <div><a class="slideshow_text_font">2. Lorem Ipsum is simply dummy text of the</a></div>
    <div><a class="slideshow_text_font">3. Contrary to popular belief, Lorem Ipsum</a></div>
    <div><a class="slideshow_text_font">4. The standard chunk of Lorem Ipsum used</a></div>
    <div><a class="slideshow_text_font">5. It is a long established fact that a</a></div>
    <div><a class="slideshow_text_font">6. There are many variations of passages</a></div>    
  </div>

  <div>
    <a class="slideshow_text_font" onclick="setSlide(0)">Show slide 01</a><br />
    <a class="slideshow_text_font" onclick="setSlide(1)">Show slide 02</a><br />
    <a class="slideshow_text_font" onclick="setSlide(2)">Show slide 03</a><br />
    <a class="slideshow_text_font" onclick="setSlide(3)">Show slide 04</a><br />
    <a class="slideshow_text_font" onclick="setSlide(4)">Show slide 05</a><br />
    <a class="slideshow_text_font" onclick="setSlide(5)">Show slide 06</a>
  </div>

I have a JQuery slideshow where some text/slide fades in and out.

At the same time I have a navigation/spots to click. When you click on a spot the slide/text changes.

The problem is when the text/slide is fading and the user clicks on a spot, the fading is interrupted. And if the user clicks on all the spots fast, then there is text from different slides that is shown at the same time.

I want the fading to end and then the users can click. In short: when fading no click.

I have made a little example that shows the problem.

Head-part of the html:

<style type="text/css">
     .slideshow
     {
         width:600px;
         height:30px;
         background-color:#0FF;                      
         overflow:hidden;
         margin:50px;
     }
     .slideshow_text_font
     {
         font:Verdana, Geneva, sans-serif;
         font-size:22px;
         font-weight:bold;       
     }
  </style>

  <script type="text/javascript" src="js/jquery.min.js"></script>
  <script type="text/javascript" src="js/jquery.cycle.all.latest.js"></script>

  <script type="text/javascript"> 
     $(document).ready(function() {
         $('.slideshow').cycle({                        
            fx: 'custom',
             sync: 0,
             cssBefore: {
                 opacity:0,
                 display: 'block'
             },
             animIn:  {
                 opacity:1               
             },
             animOut: {
                 opacity:0
             },
             timeout:5000,
             speed:2000
         });
     });

     if (document.images) {
         function setSlide(index) { 
           $('.slideshow').cycle(index);
         } 
     }
   </script>

Body-part of the html:

<div class="slideshow">
    <div><a class="slideshow_text_font">1. Some text for slide number one</a></div>
    <div><a class="slideshow_text_font">2. Lorem Ipsum is simply dummy text of the</a></div>
    <div><a class="slideshow_text_font">3. Contrary to popular belief, Lorem Ipsum</a></div>
    <div><a class="slideshow_text_font">4. The standard chunk of Lorem Ipsum used</a></div>
    <div><a class="slideshow_text_font">5. It is a long established fact that a</a></div>
    <div><a class="slideshow_text_font">6. There are many variations of passages</a></div>    
  </div>

  <div>
    <a class="slideshow_text_font" onclick="setSlide(0)">Show slide 01</a><br />
    <a class="slideshow_text_font" onclick="setSlide(1)">Show slide 02</a><br />
    <a class="slideshow_text_font" onclick="setSlide(2)">Show slide 03</a><br />
    <a class="slideshow_text_font" onclick="setSlide(3)">Show slide 04</a><br />
    <a class="slideshow_text_font" onclick="setSlide(4)">Show slide 05</a><br />
    <a class="slideshow_text_font" onclick="setSlide(5)">Show slide 06</a>
  </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狼亦尘 2024-12-16 10:27:10

您可以使用添加此插件代码来阻止所有点击:

(function($) {
    var blocker = $("<div/>", {
            id: "clickBlocker",
            style: 'position:absolute; top:0; left:0; width:100%; height:100%; z-index:100000; display:none; background:url(#);'
        }).click(function(e) {
            e.stopPropagation();
        });

    $.fn.blockClicks = $.blockClicks = function() {
        if(arguments[0]===false) {
            blocker.hide();
        } else {
            blocker.show();
        }
        return (typeof this=="function") ? undefined : this;
    }

    $(function() {
        $("body").append(blocker);
    });
})(jQuery);

要开始阻止所有点击,请在链接时使用 .blockClicks() ,或者仅使用 $.blockClicks();停止阻止点击,只需发送false

$.blockClicks(false);

请参阅此jsfiddle 进行演示。

You could use add this plugin code to block all clicks:

(function($) {
    var blocker = $("<div/>", {
            id: "clickBlocker",
            style: 'position:absolute; top:0; left:0; width:100%; height:100%; z-index:100000; display:none; background:url(#);'
        }).click(function(e) {
            e.stopPropagation();
        });

    $.fn.blockClicks = $.blockClicks = function() {
        if(arguments[0]===false) {
            blocker.hide();
        } else {
            blocker.show();
        }
        return (typeof this=="function") ? undefined : this;
    }

    $(function() {
        $("body").append(blocker);
    });
})(jQuery);

To start blocking all clicks, use .blockClicks() while chaining, or just use $.blockClicks(); To stop blocking clicks, just send false:

$.blockClicks(false);

See this jsfiddle for a demonstration.

潇烟暮雨 2024-12-16 10:27:10

尝试将 prevNextEvent 设置为 null

Try setting prevNextEvent to null.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文