I got soft rejections for javascripts / jQuery.
Reviewer sent 2 issues-
-
PROPER EVENT BINDING: Consider using the preferred .on() method rather than .click(), .bind(), .hover(), etc. For best performance and concise code use event delegation whenever possible: http://code.tutsplus.com/tutorials/quick-tip-javascript-event-delegation-in-4-minutes--net-8961
-
JQUERY PERFORMANCE NEEDS IMPROVEMENT: Your jQuery code can benefit from some performance tweaks. Please make sure that your jQuery is properly formatted, commented and that you are caching and chaining whenever possible. For more information please read: http://code.tutsplus.com/tutorials/10-ways-to-instantly-increase-your-jquery-performance--net-5551
Here is my js codes-
(function () {
"use strict";
// 0. Preloader
(window).on(‘load’, function () {
('body').addClass('preloader-hide');
});
// 1. Desktop and Mobile menu
(’.offcanvas-content ul.mobile-menu > li:has(ul)’).addClass(“has-sub”);
('.header-navigation-menu li:has(ul)').addClass("menu-item-has-children");
(’.offcanvas-content ul.mobile-menu > li:has(ul) > a’).after(’’);
('.offcanvas-content ul.mobile-menu > li > .caret').on('click', function (e) {
e.preventDefault();
var checkElement = (this).next();
('.offcanvas-content ul.mobile-menu > li').removeClass('menu-active');
(this).closest(‘li’).addClass(‘menu-active’);
if ((checkElement.is(’.submenu-inner’)) && (checkElement.is(’:visible’))) {
(this).closest('li').removeClass('menu-active');
checkElement.slideUp('normal');
}
if ((checkElement.is('.submenu-inner')) && (!checkElement.is(':visible'))) {
(’.offcanvas-content ul.mobile-menu .submenu-inner:visible’).slideUp(‘normal’);
checkElement.slideDown(‘normal’);
}
if (checkElement.is(’.submenu-inner’)) {
return false;
} else {
return true;
}
});
$(’.canvas-menu.menu-offcanvas > a.dropdown-toggle’).on(‘click’, function (e) {
e.preventDefault();
var style = (this).data(‘canvas’);
if ($(’.offcanvas-content’ + style).hasClass('open')) {
(’.offcanvas-content’ + style).removeClass('open');
(’#site-overlay’).removeClass(‘open’);
('#wp-main-content').removeClass('blur');
} else {
(’.offcanvas-content’ + style).addClass('open');
(’#site-overlay’).addClass(‘open’);
('#wp-main-content').addClass('blur');
}
});
(’#site-overlay’).on(‘click’, function (e) {
e.preventDefault();
(this).removeClass('open');
(’.offcanvas-content’).removeClass(‘open’);
('#wp-main-content').removeClass('blur');
});
(’.close-canvas’).on(‘click’, function (e) {
e.preventDefault();
('.offcanvas-content').removeClass('open');
(’#site-overlay’).removeClass(‘open’);
$(’#wp-main-content’).removeClass(‘blur’);
});
// 2. Back to top scroll
var backToTop = (’.back-to-top’);
if ($backToTop.length > 0) {
backToTop.on('click', function (e) {
e.preventDefault();
(‘html,body’).animate({
scrollTop: ‘0px’
}, 700);
});
$(window).on('scroll', function () {
var scrollPosition = $(window).scrollTop();
var windowHeight = $(window).height() / 2;
if (scrollPosition > windowHeight) {
$backToTop.addClass('in');
} else {
$backToTop.removeClass('in');
}
});
}
// 3. Background image
$("[data-background]").each(function () {
$(this).css("background-image", "url(" + $(this).attr("data-background") + ")")
});
// 4. Search click expand
if ($(".header-search-btn").length) {
$('.header-search-btn').on('click', function () {
$('.full-bar-search-wrap').toggleClass('active');
return false;
});
}
// 5. Video popup
$('.video-popup a').magnificPopup({
type: 'iframe'
});
// 6. Text animated counter
$('.counter-block').appear(function () {
var $endNum = parseInt(jQuery(this).find('.count-number').text());
jQuery(this).find('.count-number').countTo({
from: 0,
to: $endNum,
speed: 5000,
refreshInterval: 60,
formatter: function (value, options) {
value = value.toFixed(options.decimals);
value = value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return value;
}
});
}, {
accX: 0,
accY: 0
});
// 7. Year Text animated counter
$('.experience-counter').appear(function () {
var $endNum = parseInt(jQuery(this).find('.year-counter').text());
jQuery(this).find('.year-counter').countTo({
from: 0,
to: $endNum,
speed: 5000,
refreshInterval: 60,
formatter: function (value, options) {
value = value.toFixed(options.decimals);
value = value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return value;
}
});
}, {
accX: 0,
accY: 0
});
// 8. Parallax Scene
if ($('.parallax-section').length) {
var scene = $('.parallax-section').get(0);
var parallaxInstance = new Parallax(scene);
};
if ($('.call-block-parallax').length) {
var scene = $('.call-block-parallax').get(0);
var parallaxInstance = new Parallax(scene);
};
// 9. Team carousel
$('.team-carousel').owlCarousel({
loop: true,
margin: 30,
nav: false,
responsive: {
0: {
items: 1
},
600: {
items: 2
},
1000: {
items: 3
},
1200: {
items: 4
}
}
});
// 10. Partner carousel
$('.partner-carousel').owlCarousel({
loop: true,
margin: 30,
nav: false,
dots: false,
responsive: {
0: {
items: 1
},
600: {
items: 3,
margin: 80,
},
1000: {
items: 5,
margin: 130,
}
}
});
// 11. Testimonials carousel
$('.testimonial-slider').owlCarousel({
loop: true,
margin: 30,
nav: true,
dots: false,
navText: ['<span class="fal fa-arrow-left"></span>', '<span class="fal fa-arrow-right"></span>'],
responsive: {
0: {
items: 1,
margin: 0
},
600: {
items: 1
},
1000: {
items: 1
}
}
});
// 12. Testimonials carousel 2
$('.testimonials-style-two').owlCarousel({
loop: true,
margin: 30,
nav: false,
dots: true,
responsive: {
0: {
items: 1
},
600: {
items: 1
},
1000: {
items: 1
}
}
});
// 13. Portfolio carousel
$('.portfolio-carousel').owlCarousel({
loop: true,
margin: 30,
nav: true,
dots: false,
navText: ['<span class="fal fa-arrow-left"></span>', '<span class="fal fa-arrow-right"></span>'],
responsive: {
0: {
items: 1
},
600: {
items: 2
},
1000: {
items: 3
}
}
});
// 14. Portfolio carousel 2
$('.portfolio-carousel-2').owlCarousel({
loop: true,
margin: 30,
items: 2,
nav: false,
dots: true,
center: true,
navText: ['<span class="fal fa-arrow-left"></span>', '<span class="fal fa-arrow-right"></span>'],
responsive: {
0: {
items: 1
},
600: {
items: 1,
center: true,
},
900: {
items: 1,
stagePadding: 200,
center: true,
nav: true
},
1000: {
items: 1,
stagePadding: 250,
center: true,
nav: true
},
1200: {
items: 1,
stagePadding: 450,
center: true,
nav: true
},
1600: {
items: 1,
stagePadding: 550,
center: true,
nav: true
}
}
});
// 15. Post slider
$('.post-slider').owlCarousel({
loop: true,
margin: 30,
nav: false,
dots: false,
responsive: {
0: {
items: 1
},
600: {
items: 2
},
1000: {
items: 3,
margin: 60,
}
}
});
// 16. Post slider 2
$('.post-slider-2').owlCarousel({
loop: true,
margin: 30,
nav: false,
dots: false,
responsive: {
0: {
items: 1
},
600: {
items: 1
},
1000: {
items: 2,
margin: 60,
}
}
});
// 17. Micro slider for home page
$('.micro-slider').owlCarousel({
loop: true,
animateOut: "animate__slideOutLeft",
animateIn: "animate__fadeIn",
smartSpeed: 500,
autoplay: 6000,
autoplayTimeout: 7000,
margin: 0,
nav: false,
dots: true,
items: 1,
navText: ['<span class="fal fa-arrow-left"></span>', '<span class="fal fa-arrow-right"></span>'],
responsive: {
0: {
dots: false
},
600: {
dots: false
}
}
});
// 18. Service slider
$('.service-slider').owlCarousel({
loop: true,
margin: 30,
nav: false,
dots: false,
items: 1,
responsive: {
0: {
items: 1
},
600: {
items: 2
},
1000: {
items: 3
}
}
});
// 19. Testimonials slider
$('.tw-slider').owlCarousel({
loop: true,
margin: 0,
nav: false,
dots: false,
items: 1
});
// 20. About block
$('.about-block').on('hover', function () {
$(this).find('.about-block-description').slideToggle(400);
return false;
});
// 21. FAQ accordion
if ($('.accrodion-widget').length) {
var accrodionGroup = $('.accrodion-widget');
$('.accrodion-box').first().addClass('active');
accrodionGroup.each(function () {
var accrodionName = $(this).data('ag-name');
var Self = $(this);
var accordion = Self.find('.accrodion-box');
Self.addClass(accrodionName);
Self.find('.accrodion-box .accrodion-content').hide();
Self.find('.accrodion-box.active').find('.accrodion-content').show();
accordion.each(function () {
$(this).find('.accrodion-title').on('click', function () {
if ($(this).parent().parent().hasClass('active') === false) {
$('.accrodion-widget.' + accrodionName).find('.accrodion-box').removeClass('active');
$('.accrodion-widget.' + accrodionName).find('.accrodion-box').find('.accrodion-content').slideUp();
$(this).parent().parent().addClass('active');
$(this).parent().parent().find('.accrodion-content').slideDown();
};
});
});
});
};
// 22. Progress Bar
if ($('.bar-line-active').length) {
$('.bar-line-active').appear(function () {
var el = $(this);
var percent = el.data('percent');
$(el).css('width', percent).addClass('counted');
}, {
accY: -50
});
}
})(jQuery);
Please suggest me how I can fix it.