jQuery中的slideDown()和slideUp()效果问题

时间:2011-07-20 18:09:53

标签: jquery

当你在相应的<li>标签上移动时,我想要一个特定div的滑动和滑动效果。您可以通过此链接http://mashup2.sunnydsouza.com/index3.php

进行查看

使用以下jQuery来解决它

$(".altbgcolor").mouseenter(function() {
                $(this).css("background-   color","#D3EAC7").find(".newsthumb").corner();
                $(".newstext h1",this).css("color","#000");
                $(".newstext div",this).css("color","#000"); 
                $(".sharedp").slideDown(slow);

            }).mouseleave(function () {
                $(this).css("background-color","#f5f5f5").find(".newsthumb").corner();
                $(".altbgcolor:even").css("background-color","#f0f0f0");
                $(".newstext h1",this).css("color","#666666");
                $(".newstext div",this).css("color","#666666"); 
                $(".sharedp").slideUp(slow);
            });

我做错了什么。有人可以检查网站的HTML,看看哪里出错了。我在这里遇到了这个大困境:(

3 个答案:

答案 0 :(得分:2)

试试这个:

 $(".sharedp").slideUp("slow");.

慢应该是一个字符串

答案 1 :(得分:1)

如果这是代码的直接副本,则需要在slideUp / down函数的引号中加上“”。

答案 2 :(得分:1)

把引号放慢..

$(".sharedp").slideDown('slow');

$(".sharedp").slideUp('slow');

<强>更新

要将slideUp / Down限制为下一个.sharedp元素,请使用

$(".altbgcolor").mouseenter(function() {
                $(this).css("background-color","#D3EAC7").find(".newsthumb");
                $(".newstext h1",this).css("color","#000");
                $(".newstext div",this).css("color","#000"); 
                $(this).next(".sharedp").slideDown('slow');

            }).mouseleave(function () {
                $(this).css("background-color","#f5f5f5").find(".newsthumb");
                $(".altbgcolor:even").css("background-color","#f0f0f0");
                $(".newstext h1",this).css("color","#666666");
                $(".newstext div",this).css("color","#666666"); 
                $(this).next(".sharedp").slideUp('slow');
            });

您会注意到我删除了.corner方法,这种方法似乎导致脚本无声失败...

如果您创建了描述所需样式的类,并且只是使用jquery来添加/删除这些类,那么在速度和维护方面会更好。


发现了一些错误

  • title="Traffic Exchange""应该有一个结尾"
  • 数字元素的ID。只有HTML5允许使用数字ID,否则请查看规范http://www.w3.org/TR/html4/types.html#h-6.2
  • 重复的ID。 ID在文档中应该是唯一的。
  • <div class="newsthumb" center center no-repeat;"> center center no-repeat;"不应该在那里
  • div下的ul元素无效。只有li和其他ul元素可以在ul下,其余应该在里面 li

以及更多..一般来说,你应该争取有效的HTML。 验证者可以为您提供帮助,例如http://validator.w3.org/check?uri=http%3A%2F%2Fmashup2.sunnydsouza.com%2Findex3.php&charset=%28detect+automatically%29&doctype=Inline&group=1&verbose=1&user-agent=W3C_Validator%2F1.2