I have a page where the user selects one from the list of animations and clicks the confirm button, and the animation is applied to the tags entered by the user.
Everything is fine for the first time, but when the user selects a new animation , a problem occurs
When everything is fine : _link When a new animation is entered : _link
my object something like this :
[{
'target_tag': '.box-1',
'animation_status': 'animation-1',
...}
,
{'target_tag': '.box-2',
'animation_status': 'animation-2',
...},]
handle functuin :
document.querySelector(".page_frame").onclick = preview;
function preview() { var data = '';
// ------------- check feilds is empty or not
var feilds = jQuery(".sts_create input").filter('[type="text"]');
for (var i = 0; i < feilds.length; i++) {
if (feilds[i].value == "") {
new novaAlert({
icon: "danger",
title: "خطا",
text: "یک یا چند کادر خالی یافت شد لطفا تمامی کادر هارا با دقت پر کنید",
confirmButtonText: "متوجه شدم",
dismissButton: false,
}).then();
}
}
const sts_mode = jQuery('.sts_create input[type="radio"]:checked').val();
// alert(sts_mode)
const obj = jQuery(".sts_create form").serializeArray();
const collate = (obj) => {
const result = [{}];
for (const [_, input_info] of Object.entries(obj)) {
// check to see if the last item in the results array has an entry for the
// current input name, create a new object at the end of the array if it does
if (
input_info.name != "target_page_name" &&
input_info.name != "target_page" &&
input_info.name != "sts_mode"
) {
if (result[result.length - 1].hasOwnProperty(input_info.name))
result.push({});
// add entry to object at end of result array
result[result.length - 1][input_info.name] = input_info.value;
}
}
// convert result array to object
return Object.fromEntries(Object.entries(result));
};
data = collate(obj);
let x = "";
console.log(data);
for (var item in data) {
x = data[item];
if(remove____animation(x.target_tag)) {
if (sts_mode == "show-after-page-load") {
page____load(x);
} else if (sts_mode == "show-when-element-seeing") {
page____scroll(x);
}
}
}
}
main function :
function page____scroll(obj){
if (obj.target_tag != "") {
document.querySelector('.page_frame').addEventListener('scroll',()=>{
var all_elements = jQuery(
".frame " + obj.target_tag
);
for (var i = 0; i < all_elements.length; i++) {
var _innerHeight = window.innerHeight;
var elm = all_elements[i].getBoundingClientRect().top;
if (elm < _innerHeight - 200) {
jQuery(all_elements[i]).css("animation-duration", obj.duration);
jQuery(all_elements[i]).css(
"animation-delay",
obj.animation_delay
)
jQuery(all_elements[i]).attr('data-animation',obj.animation_status);
}
else if(obj.sts_show_again == 'on') {
jQuery(all_elements[i]).attr('data-animation','hidden');
}
}
})
}
}
I guess the previous animation will not be deleted at all...