预览图像淡入
Preview image fadein
我有一个表单,它使用此处找到的这个小脚本将当前上传的图像输出到访问者的浏览器本身。图像的输出太突兀。如何制作此脚本以将图像fadein
到div #blah 中。
<script>
$(document).ready(function() {
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#image-one").change(function(){
readURL(this);
});
});
</script>
如果有帮助,这里是 html。提前谢谢。
<fieldset class="images">
<label for="image" class="label">UPLOAD IMAGE :</label>
<input type="file" name="image-one" id="image-one" tabindex="25" required=""/>
</fieldset>
<div class="inline-image-preivew">
<img id="blah" src="#" width="300" align="center"/>
</div>
你应该先隐藏预览类。
.CSS
.inline-image-preivew
{
display:none;
}
然后在你的readeronload中,你可以使用.show/.toggle jquery命令。
reader.onload = function (e) {
$('#blah').attr('src', e.target.result);
$('.inline-image-preview')fadeIn( "slow", function() {
// Animation complete
});
您还可以决定其他选项:http://api.jquery.com/show/
我认为这就是你要找的。
您可以使用 CSS3 过渡或 jQuery 库使图像淡入淡出。
这是使用jQuery.fadeIn()
的小提琴
http://jsfiddle.net/Q5KtC/1/
(在您的情况下,您将基于正在上传的图像而不是按钮点击(
// With the element initially hidden, we can show it slowly:
$( "#clickme" ).click(function() {
$( "#kitten" ).fadeIn( "slow", function() {
// Animation complete
});
});
使用您的代码,这应该是这样的:
附加的 CSS
#blah
{
display : none;
}
JavaScript 代码
$(document).ready(function() {
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah')
.attr('src', e.target.result)
.fadeIn("slow");
}
reader.readAsDataURL(input.files[0]);
}
}
$("#image-one").change(function(){
readURL(this);
});
});
作为替代方案,这里有一篇关于 CSS 过渡不透明度的博客文章的链接:
http://bavotasan.com/2011/a-simple-fade-with-css3/
相关文章:
- Javascript将图像src更改为淡入淡出
- 淡入不带HTML的背景图像
- 具有淡入淡出效果的全背景图像
- 淡入背景图像淡入该分区内的内容
- jquery自动淡入淡出一系列图像
- 滑动/淡入淡出背景图像
- jQuery图像淡入淡出不起作用
- 通过设置SRC数据Javascript平滑淡入图像RGB
- 在淡入之前100%完全显示图像
- Jquery 在网站加载时淡入图像
- j查询在使用 JSON 更改 attr src 时如何淡出和淡入图像
- jQuery :加载属性更改时淡入图像
- 在 ajax 请求后完全加载后淡入图像
- 淡入图像
- 加载时淡入图像
- 仅在完成加载后才淡入图像
- 如何一个接一个地淡入图像
- JQuery addClass不透明度函数淡入图像-解决问题
- jQuery-悬停时淡入图像和文本
- 向下滚动页面时淡入图像