jquery点击.addClass问题

发布于 2024-11-10 09:29:51 字数 297 浏览 6 评论 0原文

嗨,我一整天都遇到了麻烦,它几乎可以工作,但不完全,我需要相应的 p (#p-1 等)在单击缩略图后保持突出显示。我使用了图像滑块的插件,我对其进行了稍微自定义,并且 mouseover 和 mouseleave 事件工作正常,但单击事件似乎没有将类添加到目标段落。

jsfiddle 上的示例 http://jsfiddle.net/RVYnb/7/

相关的 jQuery 内联编写的例子。

这让我发疯,请帮忙!

Hi i have been having trouble all day with this, it almost works but not quite, i need the corresponding p (#p-1 etc) to stay highlighted once the thumb nail is clicked. I have used a Plug in for an image slider which i have customized slightly and the mouseover and mouseleave events are working fine but the click event doesn't appear to add the class to the target paragraph.

Example on jsfiddle http://jsfiddle.net/RVYnb/7/

The relevant jQuery is written inline on the example.

this is driving me crazy, please help!

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

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

发布评论

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

评论(2

再见回来 2024-11-17 09:29:51

错误出在图像滑块插件中。它还绑定到代码中的单击事件。

这是插件中的相关代码部分:

jQuery("div#thumbSlider" + j + " a").each(function(z) {            
            jQuery(this).bind("click", function(){
                jQuery(this).find("p.tmbrdr").css({borderColor: settings.thumbsActiveBorderColor, opacity: settings.thumbsActiveBorderOpacity});
                jQuery(this).parent().parent().find("p.tmbrdr").not(jQuery(this).find("p.tmbrdr")).css({borderColor: settings.thumbsBorderColor, opacity: settings.thumbsBorderOpacity});
                var cnt = -(pictWidth*z);
                (cnt != container.find("ul").css("left").replace(/px/, "")) ? container.find("span.typo").animate({"opacity": 0}, 250) : null ;
                container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc, function(){container.find("span.typo").animate({"opacity": settings.typoFullOpacity}, 250)});                    
                return false;
            });
        });

问题是最后的“return false”。它会停止传播到其他点击事件。

将代码更改为以下内容:

Query(this).bind("click", function(e){
                    jQuery(this).find("p.tmbrdr").css({borderColor: settings.thumbsActiveBorderColor, opacity: settings.thumbsActiveBorderOpacity});
                    jQuery(this).parent().parent().find("p.tmbrdr").not(jQuery(this).find("p.tmbrdr")).css({borderColor: settings.thumbsBorderColor, opacity: settings.thumbsBorderOpacity});
                    var cnt = -(pictWidth*z);
                    (cnt != container.find("ul").css("left").replace(/px/, "")) ? container.find("span.typo").animate({"opacity": 0}, 250) : null ;
                    container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc, function(){container.find("span.typo").animate({"opacity": settings.typoFullOpacity}, 250)});                    
                    e.preventDefault();
                });
            });

它应该可以工作。

The error is in the image slider plugin. It also binds to the click event in the code.

Here's the relevant code part in the plugin:

jQuery("div#thumbSlider" + j + " a").each(function(z) {            
            jQuery(this).bind("click", function(){
                jQuery(this).find("p.tmbrdr").css({borderColor: settings.thumbsActiveBorderColor, opacity: settings.thumbsActiveBorderOpacity});
                jQuery(this).parent().parent().find("p.tmbrdr").not(jQuery(this).find("p.tmbrdr")).css({borderColor: settings.thumbsBorderColor, opacity: settings.thumbsBorderOpacity});
                var cnt = -(pictWidth*z);
                (cnt != container.find("ul").css("left").replace(/px/, "")) ? container.find("span.typo").animate({"opacity": 0}, 250) : null ;
                container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc, function(){container.find("span.typo").animate({"opacity": settings.typoFullOpacity}, 250)});                    
                return false;
            });
        });

The problem is the "return false" at the end. It stopps the propagation to other click events.

Change the code to the following:

Query(this).bind("click", function(e){
                    jQuery(this).find("p.tmbrdr").css({borderColor: settings.thumbsActiveBorderColor, opacity: settings.thumbsActiveBorderOpacity});
                    jQuery(this).parent().parent().find("p.tmbrdr").not(jQuery(this).find("p.tmbrdr")).css({borderColor: settings.thumbsBorderColor, opacity: settings.thumbsBorderOpacity});
                    var cnt = -(pictWidth*z);
                    (cnt != container.find("ul").css("left").replace(/px/, "")) ? container.find("span.typo").animate({"opacity": 0}, 250) : null ;
                    container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc, function(){container.find("span.typo").animate({"opacity": settings.typoFullOpacity}, 250)});                    
                    e.preventDefault();
                });
            });

and it should work.

仅冇旳回忆 2024-11-17 09:29:51

在我看来,根据“小提琴”,您的“点击”事件不适用于您的缩略图。它永远不会将“clicked”类添加到您的

.

我向其中添加了一个“警报”:

$("#t1").live("click", function() {
    alert('clicking');
    $("#p-1").addClass("clicked").addClass("highlighted");
});

警报从未弹出。

It looks to me, according to the "fiddle", that your "click" event isn't working on your thumbnails. It's never adding the "clicked" class to your

.

I threw an "alert" into this:

$("#t1").live("click", function() {
    alert('clicking');
    $("#p-1").addClass("clicked").addClass("highlighted");
});

and the alert never popped.

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