使用jquery获取图像的原始高度
我正在尝试创建一个使用 jQuery 来获取图像高度的函数,我已经尝试了我能找到的所有方法,但没有任何效果...
$(document).ready(function() {
window.onload = onLoad;
var array = "0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107".split("|");
function onLoad(){
$("style").html("");
var img = array[Math.floor(Math.random()*array.length)] + ".JPG";
document.getElementById("show").src = img;
var img_height = $("#show").height();
var img_hgt = img_height - 238;
alert(img_hgt);
$("#show").ready(function() {
var img_hgt = $("#show").height();
})
$("style").html("#show {position:absolute;top:0px;left:0px; -webkit-animation-name:slide_animation; -webkit-animation-duration:5s;} @-webkit-keyframes slide_animation { 0% { top:0px; } 100% { top:"+img_hgt+"px; } }");
setTimeout(onLoad,2*1000);
}
});
请帮助...
我试图通过此动画实现的目标是一种 ken -烧伤滑落效果...
I'm trying to create a function that uses jQuery to get height of image, I have tried everything I can find but nothing works...
$(document).ready(function() {
window.onload = onLoad;
var array = "0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107".split("|");
function onLoad(){
$("style").html("");
var img = array[Math.floor(Math.random()*array.length)] + ".JPG";
document.getElementById("show").src = img;
var img_height = $("#show").height();
var img_hgt = img_height - 238;
alert(img_hgt);
$("#show").ready(function() {
var img_hgt = $("#show").height();
})
$("style").html("#show {position:absolute;top:0px;left:0px; -webkit-animation-name:slide_animation; -webkit-animation-duration:5s;} @-webkit-keyframes slide_animation { 0% { top:0px; } 100% { top:"+img_hgt+"px; } }");
setTimeout(onLoad,2*1000);
}
});
Please help...
What I'm trying to achieve with this animation is a sort of ken-burns slide down effect...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个
Try this
我是这样做的:
HTML
CSS
JS
here's how i did it:
HTML
CSS
JS
这似乎工作正常:
http://jsfiddle.net/YVwZZ/
This seems to work fine:
http://jsfiddle.net/YVwZZ/
顺便提一句。这
不是一个数组。它是一个字符串。如果您尝试使用代码随机输入该字符串,您最终会得到分隔符“|”有时。
试试这个
编辑:关于数组的实现一切都很好。我忽略了行尾的
split('|')
Btw. this
is NOT an array. It is a string. If you try to get a random entry of this string with your code you'll end up getting the separator "|" sometimes.
Try this instead
EDIT: Everything is fine with your implementation regarding the array. I overlooked the
split('|')
at the end of the line