我正在尝试学习如何使用jQuery,我偶然发现了一个问题.首先,我将向您展示导致问题的代码部分.
HTML
<div id="nav"> <div id="button"><p class="scroll" onclick="location.href='#ed';">Education</p></div> <div id="button"><p class="scroll" onclick="location.href='#wxp';">Work Experience</p></div> <div id="button"><p class="scroll" onclick="location.href='#oact';">Other Activities</p></div> <div id="button"><p class="scroll" onclick="window.open('cv.pdf','mywindow');">View as PDF</p></div> <div id="arrow_container"><div class="arrow" id="down"></div></div>
jQuery的
$(document).ready(function(){ $("#arrow_container").toggle( function () { $("#nav").animate({marginTop:"0px"},200); },function () { $("#nav").animate({marginTop:"-100px"},200); }); });
我希望div #nav(最初位于屏幕外部)在单击div #arrow_container时向下移动.然后当再次单击#arrow_container时,我希望#nav向上移动到其原始位置.
目前,没有发生这种情况.你能告诉我问题是什么以及如何解决它吗?
解决方法
尝试这个:
$("#arrow_container").click( function(event){ event.preventDefault(); if ( $(this).hasClass("isDown") ) { $("#nav").stop().animate({marginTop:"-100px"},200); } else { $("#nav").stop().animate({marginTop:"0px"},200); } $(this).toggleClass("isDown"); return false; });
原文地址:https://www.jb51.cc/jquery/181006.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。