[英]can't seem to get slidetoggle to work
Note: I have searched online and tried implementing several different codes and nothing appears to work. 注意:我已经在线搜索并尝试实现几种不同的代码,但似乎没有任何效果。 The code below is the code that is currently on the test page.
下面的代码是测试页面上当前的代码。
I've got the following code. 我有以下代码。 I had this working someway or another a while back but accidentally deleted my code and now I can't get anything to work.
我曾经有一段时间工作了,但是不小心删除了我的代码,现在我什么也无法工作。
I have a hidden div at the top of the page. 我在页面顶部有一个隐藏的div。 I need to have a link that I can place anywhere that will toggle that div to display.
我需要有一个链接,该链接可以放在可以切换该div以显示的任何位置。 I would like a nice animation which is why I used slidetoggle.
我想要一个不错的动画,这就是为什么我使用slidetoggle。 I had slidetoggle working a while back with different code, but I lost the code and now nothing I do is working.
我曾经使用不同的代码运行slidetoggle,但是我丢失了代码,现在什么也没做。
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$('.Hdiv_Top').click(function(){
$("#HiddenDiv_Top").slideToggle();
return false;
});
</script>
<style>
#HiddenDiv_Top {
display:none;
}
#HiddenDiv_Top:target {
display:block;
}
</style>
<div id="HiddenDiv_Top" style="height: 150px; background: #FF9; color: #000; border-bottom: 2px solid #000; width: 100%;"> bla bla bla </div>
<ul>
<li ><a href="javascript:void(0)" class="Hdiv_Top" >Directions</a></li>
</ul>
Your code needs to be in a document ready handler because when your scripts is executed the Hdiv_Top
element is not yet loaded to the dom 您的代码需要在文档就绪处理程序中,因为执行脚本时,
Hdiv_Top
元素尚未加载到dom中。
jQuery(function($){
$('.Hdiv_Top').click(function(){
$("#HiddenDiv_Top").stop(true, true).slideToggle();
return false;
});
})
You've forgotten to wait for the entire page to load before running your jQuery script. 您已经忘记了等待整个页面加载之后再运行jQuery脚本。 The page doesn't see any element matching that class that has loaded.
该页面看不到任何与已加载的类匹配的元素。
http://jsfiddle.net/T4SCW/ http://jsfiddle.net/T4SCW/
$(function () {
$('.Hdiv_Top').click(function () {
$("#HiddenDiv_Top").slideToggle();
return false;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.