Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何使用ajax上传来改进我的照片库?_Jquery_Photo Gallery - Fatal编程技术网

Jquery 如何使用ajax上传来改进我的照片库?

Jquery 如何使用ajax上传来改进我的照片库?,jquery,photo-gallery,Jquery,Photo Gallery,我花了好几天的时间为我的网站制作一个照片库(我是一名摄影师),但是当我放照片时(一张有7-8MB,4300x3000),它们的加载速度非常慢。我在网上搜索了我该怎么做,我发现了一些关于ajax上传的东西(Facebook也在使用同样的东西,ajax)。实际上,我的图库与FB照片库非常相似,但没有评论之类的东西。我只需要照片的小缩略图,以及当你点击缩略图时照片恢复正常尺寸的效果。我创建了一个这样的照片库,唯一的问题是加载时间,它几乎使我的计算机崩溃,我没有时间手动调整每张照片的大小。那么,关于这个

我花了好几天的时间为我的网站制作一个照片库(我是一名摄影师),但是当我放照片时(一张有7-8MB,4300x3000),它们的加载速度非常慢。我在网上搜索了我该怎么做,我发现了一些关于ajax上传的东西(Facebook也在使用同样的东西,ajax)。实际上,我的图库与FB照片库非常相似,但没有评论之类的东西。我只需要照片的小缩略图,以及当你点击缩略图时照片恢复正常尺寸的效果。我创建了一个这样的照片库,唯一的问题是加载时间,它几乎使我的计算机崩溃,我没有时间手动调整每张照片的大小。那么,关于这个ajax上传,我应该知道些什么呢?我如何调用自动调整照片大小的函数,就像Facebook那样?这就是我在照片库中取得的成就(我放了一些网络照片作为例子)

HTML


您可以按如下方式实现图像大小调整功能:

var max_w = 600; // set the image maximum width
var max_h = 300; // set the image maximum height
$("img").each(function(i) { // match all img elements
    var this_w = $(this).height();
    var this_h = $(this).width();
    // check which side of the image needs to be kept to the maximum 
    if (this_w/this_h < max_w/max_h) {
        var h = max_h;
        var w = Math.ceil(max_h/this_h * this_w);
    } else { // calculate proportionally
        var w = max_w;
        var h = Math.ceil(max_w/this_w * this_h);
    }
    // assign new height and width values using CSS
    $(this).css({ height: h, width: w });
});
var max_w=600;//设置图像的最大宽度
var max_h=300;//设置图像的最大高度
$(“img”)。每个函数(i){//匹配所有img元素
var this_w=$(this).height();
var this_h=$(this).width();
//检查图像的哪一侧需要保持最大值
如果(此w/此h<最大w/最大h){
var h=最大值h;
var w=Math.ceil(max_h/this_h*this_w);
}否则{//按比例计算
var w=最大值w;
var h=Math.ceil(max_w/this_w*this_h);
}
//使用CSS指定新的高度和宽度值
$(this.css({height:h,width:w});
});

我想你在找这样的东西

var max_w = 600; // set the image maximum width
var max_h = 300; // set the image maximum height
$("img").each(function(i) { // match all img elements
    var this_w = $(this).height();
    var this_h = $(this).width();
    // check which side of the image needs to be kept to the maximum 
    if (this_w/this_h < max_w/max_h) {
        var h = max_h;
        var w = Math.ceil(max_h/this_h * this_w);
    } else { // calculate proportionally
        var w = max_w;
        var h = Math.ceil(max_w/this_w * this_h);
    }
    // assign new height and width values using CSS
    $(this).css({ height: h, width: w });
});