简体   繁体   English

javascript onclick将div向下滑动而不是删除?

[英]javascript onclick slide div down instead of remove?

I am using the following code inside my div element so when a user clicks on the link within the div the div is hidden/removed. 我在div元素中使用了以下代码,因此当用户单击div中的链接时,div会被隐藏/删除。

However, is there a way I could use the same one line of code that I am using to remove the div but instead get it to slide down to hide? 但是,有没有一种方法可以使用与删除div相同的一行代码,却可以向下滑动以隐藏它呢?

$_SESSION['password_change'] = '<div id="bottom_notification" onclick="this.parentNode.parentNode.removeChild(this.parentNode);"><div id="bottom_notification_heading"><h23>Password Change!</h23><div class="boxclose" id="boxclose">&#10006;</div></div><p>Hi, your accessing your account for the first time, so we recommend you change your password.</p><p><a href="process/change_pass.php" rel="shadowbox;height=300;width=470">Click Here</a></p></div>';

ontopic 主题

A short answer to your question would be no, you can't, not with that one line. 对您的问题的简短回答是:不能,不能,不用那一行。 Javascript does not have a default method for sliding things or animating things at all. Javascript根本没有滑动事物或动画事物的默认方法。 This all has to be written by the developer. 所有这些都必须由开发人员编写。

If you don't know how to write such things or don't know any javascript I'd recommend jQuery as a library for now but do know that if you use jQuery it's better to understand the JS behind it as well. 如果您不知道如何编写此类内容或不知道任何JavaScript,我现在建议将jQuery作为一个库,但要知道,如果您使用jQuery,则最好也理解它背后的JS。 (jQuery = a set of JS functions made for you eg library) (jQuery =为您量身定制的一组JS函数,例如库)

jQuery website jQuery网站

offtopic 无关

It's also quite weird to store chunks of a page in a php session as this is not what it's made for. 在php session存储页面的一部分也很奇怪,因为这不是它的目的。

sessions are used for saving small pieces of data or objects through page reloads / navigation through pages, in your case I would reconsider the use of PHP sessions to not store HTML but rather find a different solution to displaying the div on your page. sessions用于通过页面重新加载/页面浏览来保存少量数据或对象,在您的情况下,我将重新考虑使用PHP sessions来不存储HTML,而是寻找一种不同的解决方案来在页面上显示div。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM