首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有悬停效果的jquery carousel

问具有悬停效果的jquery carousel
EN

Stack Overflow用户
提问于 2011-02-24 06:19:06
回答 2查看 1.8K关注 0票数 1

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

下面是jQuery:

http://pastebin.com/fB16ahcZ

网站仍在大力开发中。

如果您将鼠标悬停在旋转木马上的“服务保留”上,您将看到该函数应该是什么样子的。鼠标悬停时,跨度元素会淡入,鼠标移出时会隐藏。有些卡住了,有些工作得很好。还请注意,当您单击向右箭头并在旋转木马中滚动时,跨度会卡住"on“。

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

EN

回答 2

Stack Overflow用户

发布于 2011-02-24 08:03:42

您的标记无效,因为它缺少结束的"a“标记(如下所示)

代码语言:javascript
复制
</a>

以下是代码中的错误。

代码语言:javascript
复制
           <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%。

例如,将一个id添加到您的ul中,如下所示

代码语言:javascript
复制
<ul id="mycarousel">

代码语言:javascript
复制
    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;
        });
    });

这段代码固定在当前的html结构中,你应该使用类来使它更灵活。

票数 1
EN

Stack Overflow用户

发布于 2011-02-24 08:11:23

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

代码语言: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是错误的。以下是工作原理:

代码语言: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;
            }
        );
    }
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5097935

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档