javascript – 使用jquery随机显示页面内的图像
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 使用jquery随机显示页面内的图像,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2075字,纯文字阅读大概需要3分钟。
内容图文
![javascript – 使用jquery随机显示页面内的图像](/upload/InfoBanner/zyjiaocheng/817/ccbc6db2494f4023996eb245b62bdd02.jpg)
我在页面内部连续尝试fadeIn fadeOut图像.我尝试了窗户高度.但是出现的图像溢出了窗口的宽度.这是FIDDLE
有没有办法在窗口内随机显示图像,没有溢出或任何东西.
这里是
var clone = drop
.clone()
.appendTo('body')
.css('left', Math.random() * jQuery(window).width() - 100)
.css('top', snowTop)
.html('<img src="http://i.stack.imgur.com/S9o1r.png"/>')
.animate({
}, 20000, function() {
jQuery(this).fadeIn(2000, function() {
jQuery(this).fadeOut(2000);
});
解决方法:
尝试以下代码….我刚刚使用innerHeight和innerWeight而不是高度和宽度.也改变了snowTop到以下..
var snowTop = Math.floor(Math.random() * (windowHeight-128)); //here 128 is image height..you should provide actual height of image instead of 128
JS:
jQuery(function() {
var windowHeight = jQuery(window).innerHeight();
var drop = jQuery('.drop2').detach();
var wh = jQuery(window).innerHeight();
var ww = jQuery(window).innerWidth();
var fh = jQuery('.drop2').innerHeight();
var fw = jQuery('.drop2').innerWidth();
function create() {
var snowTop = Math.floor(Math.random() * (windowHeight-128));
var number1 = windowHeight - 500 + Math.floor(Math.random() * windowHeight);
var number2 = 1 + Math.floor(Math.random() * 28);
var number3 = 9 + Math.floor(Math.random() * 4);
var number4 = 13 + Math.floor(Math.random() * 4);
var number5 = 17 + Math.floor(Math.random() * 4);
var imageSize = Math.floor(Math.random() * 20);
//alert(imageSize);
if (imageSize > 15) {
var customsize = Math.random(1 * 1000) + 9000;
} else {
var customsize = Math.random(1 * 1000) + 15000;
}
// alert(number1);
var clone = drop
.clone()
.appendTo('body')
.css('left', Math.random() * jQuery(window).innerWidth() - 128)
.css('top', snowTop)
.html('<img src="http://i.stack.imgur.com/S9o1r.png"/>')
.animate({
}, 20000, function() {
jQuery(this).fadeIn(2000, function() {
jQuery(this).fadeOut(2000);
});
jQuery(this).click(function() {
alert("Happy Holidays");
});
jQuery(this).hover(
function() {
jQuery(this).append(jQuery("<div id='new' style='width:100px;height:100px;color:#fff;'>Happy Holidays</div>"));
}, function() {
jQuery(this).find("div:last").remove();
}
);
});
}
setInterval(create, 1000);
});
内容总结
以上是互联网集市为您收集整理的javascript – 使用jquery随机显示页面内的图像全部内容,希望文章能够帮你解决javascript – 使用jquery随机显示页面内的图像所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。