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



我想要一个滑下和滑上效果在一个特定的div当你在相应的<li>标签。你可以在这个链接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,看看我在哪里出错。我现在进退两难

试试这个:

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

slow应该是字符串

用引号括起来

$(".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;"不应该在那里
  • 在无效的ul下有div元素。只有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

如果是直接复制代码,则需要在slideUp/down函数中将"slow"加引号。

最新更新