- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个小的图像调整大小脚本,它可以立即提供调整大小后的图像作为下载。如果这是正常情况,结果内容加载在同一页面的 div 中,那么下面的 js 代码就会起作用,就像在我网站的其他部分一样。但这里的情况是输出(调整大小的图像)作为强制下载提供,它显示为下载提示面板,因此下面的代码加载 load.gif 但无法隐藏它。因此,loading.gif 仍然可见。
我猜我需要以某种方式更改或修复的代码,在 JS 代码下方的第 6 行之后开始。到那时它就可以正常工作并按预期工作。请注意,我的调整大小脚本完全是用 php 编写的。
<小时/>JS
<script type="text/javascript">
jQuery(document).ready(function() {
var $pageLoad = jQuery('.page-load');
$pageLoad.hide();
jQuery('#SubmitButton').on('click', function() {
$pageLoad.show(100);
});
//code till here works fine and triggers gif on submit but dunno after this
//what codes should go here to fadeout or hide the loading gif ?
//not even sure if this is right approach
});
</script>
<小时/>
HTML:
<form action="http://xxxxxxxxxxx/wp-content/themes/xxxxx/resize/resize.php" id="UploadForm" method="post" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit" id="SubmitButton" name="SubmitButton" value="Upload" />
</form>
<小时/>
正如您所知,我在不同的 .php 页面上使用 WordPress cms 和调整大小脚本,并且该脚本使用 session_start()
。我刚学php,对JS一窍不通。是的,我也在进行自己的搜索、研究和调整。到目前为止,一切都还没有解决。如果您还需要 resize.php 中的代码以获得更好的引用,请告诉我。
为了简单起见,这里是预期序列的简单说明。
访问者点击提交按钮。
数据提交到 resize.php,如表单操作标记所示。
上面的 JS 脚本被触发并显示隐藏的 div 类“page-load”,其中包含加载 gif(以便访问者知道正在发生某些事情)。
现在调整大小过程已完成,访问者将获得下载和保存面板。
问题:表单页面已重新加载,但加载 gif 仍然可见。希望这是清楚的。
<小时/>Bottomline : How to hide the loading gif once download panel appears/image is resized.
首次更新:类似问题 described here收集选票但仍未解决。
第二次更新:我仍在寻找答案。我以为这会是在公园里散步。严重错误。
最佳答案
我决定为您介绍一下这个问题。以下是有关如何使用 ajax 构建请求的分步指南。
下面的代码创建的内容可以在 http://tomsfreelance.com/stackoverflow/imageDownloadLoading/main.php 中看到
包含 PHP 的文件包含在目录 ( http://tomsfreelance.com/stackoverflow/imageDownloadLoading/ )
第 1 步:设置表单。我们暂时保持简单。
<form name="resizeImage">
<select id="image" onChange="com.demo.updateImage();">
<option value="img1.jpg">img1.jpg</option>
<option value="img2.jpg">img2.jpg</option>
<option value="img3.jpg">img3.jpg</option>
</select>
<input type="text" id="tint" placeholder="Tint" onKeyUp="com.demo.updateTint();">
<input type="button" id="download" value="Download" onClick="com.demo.downloadImage();" />
<br />
<img style="max-width: 400px; max-height: 400px;" src="img1.jpg" id="preview">
<div id="color"></div>
</form>
第 2 步:添加一些 javascript/ajax
<script>
var com = {};
com.demo = {};
com.demo.loading = false;
com.demo.loadingBox = null;
com.demo.loadingStage = 1;
com.demo.updateImage = function() {
$('#preview').prop('src', $('#image').val());
com.demo.updateTint();
}
com.demo.updateTint = function() {
$('#color').css( {
'width': $('#preview').outerWidth() + 'px',
'height': $('#preview').outerHeight() + 'px',
'background-color': $('#tint').val(),
'z-index' : 10,
'position': 'absolute',
'left': $('#preview').position().left,
'top' : $('#preview').position().top,
'opacity' : 0.4
});
}
com.demo.doLoading = function() {
if (com.demo.loading) {
if (com.demo.loadingBox == null) {
com.demo.loadingBox = $('<div id="loading">Loading</div>').appendTo('body').css({ "position" : "absolute", "width" : "100px", "left" : "50px", "top" : "50px", "border" : "5px solid #000000", "padding" : "10px", "z-index" : "20", "background-color" : "#FFFFFF" });
}
else com.demo.loadingBox.css({ 'display' : 'block' });
com.demo.loadingStage = ++com.demo.loadingStage % 3;
var string = "Loading";
for (var x = 0; x < com.demo.loadingStage; x++) {
string += ".";
}
com.demo.loadingBox.text(string);
setTimeout(function() { com.demo.doLoading(); }, 1000);
}
else {
com.demo.loadingBox.css({ 'display' : 'none' });
}
}
com.demo.downloadImage = function() {
var data = {};
data.img = $('#image').val();
data.tint = $('#tint').val();
// Show loading box.
com.demo.loading = true;
com.demo.doLoading();
$.post("convert.php", data)
.done(function(d) {
com.demo.loading = false;
document.location.href = d;
});
}
</script>
第3步:制作处理该文件的PHP页面。
<?php
function hex2rgb($hex) {
$hex = str_replace("#", "", $hex);
if(strlen($hex) == 3) {
$r = hexdec(substr($hex,0,1).substr($hex,0,1));
$g = hexdec(substr($hex,1,1).substr($hex,1,1));
$b = hexdec(substr($hex,2,1).substr($hex,2,1));
} else {
$r = hexdec(substr($hex,0,2));
$g = hexdec(substr($hex,2,2));
$b = hexdec(substr($hex,4,2));
}
$rgb = array($r, $g, $b);
//return implode(",", $rgb); // returns the rgb values separated by commas
return $rgb; // returns an array with the rgb values
}
if (isset($_POST['img'])) {
$im = imagecreatefromjpeg($_POST['img']);
$color = (empty($_POST['tint'])) ? hex2rgb("#000000") : hex2rgb($_POST['tint']);
if (imagefilter($im, IMG_FILTER_COLORIZE, $color[0], $color[1], $color[2])) {
header('Content-Description: File Transfer');
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=download.jpg");
imagejpeg($im, "download.jpg");
echo "download.php";
}
}
第4步:制作下载页面。
<?php
header('Content-Description: File Transfer');
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=download.jpg");
readfile("download.jpg");
关于javascript - 一旦调整大小的图像提供下载,隐藏加载 gif,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19739622/
有谁知道是否可以将多个 gif 或动画 gif 加入到一个动画 gif 中(即,将这些帧连接到一个主动画 gif 中)? 我想要一些服务器端功能来执行此操作。 文件的尺寸、模式等将相同,只是内容不同。
提前道歉,但这不是一个真正的photoshop问题。相反,我试图想出一些令人信服的东西,但尽可能地利用 gif 格式的压缩和特性来为动画生成尽可能小的文件。 一些限制: 它需要至少 20 或 30 帧
如何创建播放一次并在最后一帧卡住的 GIF 图像。 我已经将循环属性设置为 1,所以第一个问题解决了。 但是动画结束后,gif并不是在最后一帧卡住,而是回到第一帧。 最佳答案 您需要将 gif 的循环
我有两个不同大小的 GIF。我希望能够将一个动画 GIF 放在特定位置的静态背景 GIF 上,同时将文本添加到结果中。我是 ImageMagick 世界的新手,请帮忙。 我试图实现以下结果,其中狗贴纸
你好 stackoverflow 世界。(这是我第一次在这里真正发布问题。令人兴奋) 不久前,我从我公司的一个团队那里继承了一个已有 2 年历史的 MVC 网站。我现在知道这个解决方案的大部分来龙去脉
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 1 年前。
我想将我的处理草图之一导出为 gif 形式,并使用 extrapixel 的 Gif 动画库 ( http://extrapixel.github.io/gif-animation/ ) 来执行此操作
我正在寻找一个可以处理动画 gif 图像并在其上写入文本的函数。 工作解决方案可能由 Gif4j lib 提供,但我正在寻找开源解决方案或建议如何自行实现它。 如何在 Java 中将文本放在 gif
这个问题在这里已经有了答案: Change File Extension Using C# (6 个答案) 关闭 8 年前。 此代码将重命名所有文件名: static private void Re
我会保持简短; 有什么方法可以区分静态 GIF 图像和动画图像吗?我正在使用 C#。 谢谢 最佳答案 Here's an article about how to determine the numb
我试图在视频上重叠动画 gif,但没有成功。 我的目标是下一个: gif 动画必须循环播放,直到视频结束。 gif 被缩放以覆盖整个视频。 gif 保留透明度。 我在这方面取得的最大成就是 gif 使
在您的网站上放置网站图标时,您显然可以使用动画 gif,只需将 gif 文件的扩展名更改为 .ico . http://www.k-director.com/blog/how-to-add-an-an
所以我试图为一个充满 gif 的文件夹添加水印,但我收到一条错误消息,说我当时只能使用一个 GIF 流,有没有办法绕过这个问题? @echo off setlocal for %%G in ("%~d
我有大约 200 张 jpg 图像。我需要堆叠它们,以便我可以将它们转换为简单的动画 gif 图像。是否有任何免费工具可以完成这项工作?我的操作系统是windows。 我不太关心输出的质量。 最佳答案
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
我想使用库显示 GIF WPF Animated GIF 。但是,当设置属性 PictureSource 时,进程内存会从 208MB 增加到 1GB。为什么? XAML
几天后我有话要说。我必须引用细胞原子。我想在显示元胞自动机进化的幻灯片中显示一个小 gif,所以我的问题是:如何将使用 golly game of life 创建的模式和进化转换为动画 gif? 最佳
看这段代码: $('#loader').show(); $.post( '/action.php', function( data ) { // do anything with data $('#
作为项目的一部分,我们需要以编程方式将多个动画 GIF 以网格的形式组合成一个主动画 GIF(一个 gif 文件)。 我们不关心它是在客户端(即带有 ios/android 的智能手机)还是在服务器端
我正在制作一个小游戏。这不是 Action 游戏,而是解谜游戏,因此性能并不是那么重要。现在,我有了主游戏区,一张背景图片。在某些情况下,我想在部分背景图像上绘制其他图像。我的问题是背景图片和叠加的图
我是一名优秀的程序员,十分优秀!