如何使网站投资组合部分中的项目下拉列表加载速度更快?

How can I make the project dropdowns in the portfolio section of my website load faster?

提问人:Praveena Dewars 提问时间:3/1/2022 更新时间:3/1/2022 访问量:31

问:

我的网站加载得很好,但是当我尝试打开我的作品集部分中的任何项目时,加载时间可能太长了 - 桌面和移动。

这是我认为可能导致这种情况的代码片段 - 我不确定要进行哪些更改来修复它,请帮忙。

谢谢

`jQuery('.portfolio-item a').on("click", function(e) {
            e.preventDefault();
            var $that = jQuery(this);
            var $item = $that.closest(".portfolio-item");
            
            if ($item.find('.loading').length===0) {
                jQuery('<div />').addClass('loading').appendTo($item);
                $that.parent().addClass('active');

                var $loading = $item.find('.loading'),
                    $container = jQuery('#portfolio-details'),
                    timer = 1;
                
                if ($container.is(':visible')) {
                    closeProject();
                    timer = 800;
                    $loading.animate({width:'70%'}, {duration:2000, queue:false});
                }

                setTimeout(function() {

                    $loading.stop(true, false).animate({width:'70%'},   
{duration:5000, queue:false});
                    
                    //Add AJAX query to the url
                    var url = $that.attr("href")+"?ajax=1";
                    
                    jQuery.get(url).done(function(response) {
                        $container.html(response);
                        
                        $container.waitForImages(function() {
                            $loading.stop(true, false).animate({width:'100%'}, 
{duration:500, queue:true});
                            
                            $loading.animate({opacity:0}, {duration:100, 
queue:true, complete:function() {
                                $that.parent().removeClass('active');
                                jQuery(this).remove();

                                $container.show().css({opacity:0}); 
                                
                                that.imageSlider($container, function() {
                                    jQuery(document).scrollTo($container, 600, 
{offset:{top:-parseInt(jQuery(".navbar").height(), 10), left:0}});
                                    $container.animate({opacity:1}, {duration:600, 
queue:false});
                                    $container.attr('data-current', 
$that.data("rel"));
                                });
                            }});
                        });`
jquery jquery -移动

评论

1赞 Kinglish 3/1/2022
通常,您的脚本正在等待 ajax(我测试的脚本需要 1.23 秒才能加载),然后等待图像完全加载,然后再滚动到目标。用户体验不好。重新调整它,使其首先滚动到屏幕,然后显示正在加载的内容。这样,用户就知道发生了什么。现在,它似乎没有反应(暂时)
0赞 Praveena Dewars 3/2/2022
谢谢,知道它的代码会是什么样子吗?

答: 暂无答案