【问题标题】:jquery carousel with hover effects带有悬停效果的jQuery轮播
【发布时间】:2011-02-23 22:19:05
【问题描述】:

这是网址:http://174.120.239.48/~peakperf/

这是 jQuery:

http://pastebin.com/fB16ahcZ

网站仍在大力开发中。

如果您将鼠标悬停在轮播上的“服务保留”上,您将看到该功能的工作方式。悬停时跨度元素淡入,鼠标移出时隐藏。有些卡住了,有些工作正常。另请注意,当您单击向右箭头并滚动轮播时,跨度会卡在“打开”状态。

任何帮助将不胜感激,谢谢!

【问题讨论】:

    标签: javascript jquery css jquery-selectors carousel


    【解决方案1】:

    您的标记无效,因为它缺少结束的“a”标记(见下文)

    </a>
    

    这是您的代码中的错误。

               <a href="#" id="homeslide6-show">
                   <img src="http://174.120.239.48/~peakperf/wp-content/themes/strausberg/images/home_service_retention.jpg" width="200" height="92" />
              </li>
          </ul>
    

    此外,通过使用 each() 函数,您的 jquery 代码可以减少大约 90%。

    例如,在你的 ul 中添加一个 id 并这样做

    <ul id="mycarousel">
    

        jQuery('#mycarousel').find('span').each(function(){
    
            jQuery(this).hover(function() {
    
                jQuery(this).next().fadeIn('slow');
    
                return false;
    
            }, function(){
    
                jQuery(this).next().fadeOut('slow');
    
                return false;
            });
        });
    

    Ps,这段代码是固定到当前的html结构的,你应该使用类使它更灵活

    【讨论】:

    • 我试过你的代码,但我的跨度没有显示在悬停时,即使我的轮播有一个 id。感谢您的帮助,非常感谢。我会继续努力,看看我能想出什么。
    • 你修复了你的 html,并将 id 放到轮播中,并使用了 jquery 的其他部分与我的结合吗?
    【解决方案2】:

    您似乎有多个具有相同 ID 的标签,这是不允许的。 ID 是"homeslide6-show"。在启动 JavaScript 之前,您还应该尝试停止动画并将其简化为:

    jQuery(document).ready(function() {
    
        // hides the slickbox as soon as the DOM is ready
        jQuery('#homeslide1, #homeslide2, #homeslide3, #homeslide4, #homeslide5, #homeslide6').hide();
    
        // shows the slickbox on clicking the noted link  
        for (var i = 1; i <= 6; i++) {
            jQuery('#homeslide' + i + '-show').parent().hover(
                function(e, i) {
                    jQuery('#homeslide' + i).stop(true, true).fadeIn('slow');
                    e.preventDefault();
                    return false;
                },
                function(e, i){
                    jQuery('#homeslide' + i).stop(true, true).fadeOut('slow');
                    e.preventDefault();
                    return false;
                }
            );
        }
    });
    

    如果可行,请告诉我。

    已编辑

    我上面的 javascript 不正确。以下作品:

    jQuery(document).ready(function() {
    
        // hides the slickbox as soon as the DOM is ready
        jQuery('#homeslide1, #homeslide2, #homeslide3, #homeslide4, #homeslide5, #homeslide6').hide();
    
        // shows the slickbox on clicking the noted link  
        for (var i = 1; i <= 6; i++) {
            jQuery('#homeslide' + i + '-show').parent().data({element: '#homeslide' + i}).hover(
                function() {
                    var element = jQuery('element');
                    jQuery(element).stop(true, true).fadeIn('slow');
                    return false;
                },
                function(){
                    var element = jQuery('element');
                    jQuery(element).stop(true, true).fadeOut('slow');
                    return false;
                }
            );
        }
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-26
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    • 1970-01-01
    • 2021-11-12
    相关资源
    最近更新 更多