I'm trying to do scrollUp and scrollDown with a native JS Element.animate()
. I want the element to appear smoothly from the top to the bottom. What I get is an immediate opening and delayed collapsing. If there are currently better ways to do it, I'd like to know, I'm still curious why doesn't this work though.
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('addNewScriptStep').onclick = function() {
let list = document.getElementById('collapsibleActionList');
let newHeight = '100%';
if (list.dataset.iscollapsed == 'false') {
newHeight = '0';
}
list.dataset.iscollapsed = !eval(list.dataset.iscollapsed);
list.animate({
height: newHeight
}, {
fill: 'forwards',
duration: 500
});
};
});
#collapsibleActionList {
overflow: hidden;
height: 0;
transition: height 0.5s;
}
<html>
<body>
<a href="javascript:void(0)" id="addNewScriptStep" class=""> Add an action </a>
<ul id="collapsibleActionList" data-iscollapsed="true">
<li data-type="open_url">Open URL</li>
<li data-type="href_to">Click link</li>
<li data-type="click_element">Click element</li>
<li data-type="insert_into">Insert into textbox</li>
<li data-type="sleep">Sleep</li>
<li data-type="checked">Check checkbox</li>
<li data-type="unchecked">Uncheck checkbox</li>
<li data-type="send_form">Submit form</li>
<li data-type="if_element_is_defined">Continue if HTML contains element</li>
<li data-type="if_element_is_not_defined">Continue if HTML doesn't contain element</li>
<li data-type="if_text_is_defined">Continue if there is text</li>
<li data-type="if_text_is_not_defined">Continue if there is no text</li>
</ul>
</body>
</html>
Edit: I noticed that after removing CSS transition property, the list can no longer collapse, though animate function IS being called with {height: '0'}