admin管理员组文章数量:1334150
I've got a page of elements, each of which, depending on user interaction, may be animated away by the given function:
function slideAndFade(id){
$(id).animate({opacity: 'toggle', width: 'toggle'}, 500);
}
I want to create a reset function that brings all the elements back onto the page. Running all the elements through the toggle function above won't work, because currently hidden elements will be shown, and currently shown elements will be hidden.
Essentially looking for way to revert all elements to their original css states, regardless of whether they've been acted upon by jquery animation.
Thanks-
Edit:
Just realized all I need to do is replace 'toggle' with 'show':
function revertSlideAndFade(id){
$(id).animate({opacity: 'show', width: 'show'}, 500);
}
Calling this on any element will ensure the element is reverted back to visible in this case. However, see Nick's answer below for a more generally applicable approach.
I've got a page of elements, each of which, depending on user interaction, may be animated away by the given function:
function slideAndFade(id){
$(id).animate({opacity: 'toggle', width: 'toggle'}, 500);
}
I want to create a reset function that brings all the elements back onto the page. Running all the elements through the toggle function above won't work, because currently hidden elements will be shown, and currently shown elements will be hidden.
Essentially looking for way to revert all elements to their original css states, regardless of whether they've been acted upon by jquery animation.
Thanks-
Edit:
Just realized all I need to do is replace 'toggle' with 'show':
function revertSlideAndFade(id){
$(id).animate({opacity: 'show', width: 'show'}, 500);
}
Calling this on any element will ensure the element is reverted back to visible in this case. However, see Nick's answer below for a more generally applicable approach.
Share Improve this question edited May 23, 2017 at 12:24 CommunityBot 11 silver badge asked Sep 1, 2010 at 15:34 YarinYarin 184k155 gold badges410 silver badges524 bronze badges1 Answer
Reset to default 5If you could identify all the elements that might be passed into this function, say they had a class .toggleElem
you could use that to store the values on page load and restore then when needed, like this:
$(function() {
$(".toggleElem").each(function() {
var $this = $(this);
$.data(this, 'css', { opacity: $this.css('opacity'),
width: $this.css('width') });
});
});
Then you could restore them at any point later:
function restore() {
$(".toggleElem").each(function() {
var orig = $.data(this, 'css');
$(this).animate({opacity: orig.opacity, width: orig.width}, 500);
});
}
本文标签: javascriptReverting jquery animations back to original css statesStack Overflow
版权声明:本文标题:javascript - Reverting jquery animations back to original css states - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742246824a2440007.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论