【发布时间】:2014-09-07 13:03:56
【问题描述】:
我希望将图像的宽度设置为 25% 到 75% 之间的随机数,这可以通过 Jquery 实现吗?到目前为止,我已经尝试了我能想到和研究的一切,但无济于事..
有人可以帮忙吗?
我对 JQuery 不太了解,因此非常感谢您的帮助
我正在尝试使用插件 Instafeed 从带有特定主题标签的用户帐户中随机化图像大小,因此我完全拥有:
我需要 .insta-box 在每次加载图像时随机生成一个大小...
<style>
.insta-box {float:center;clear:both;margin:0px;padding:0%;max-height:50%;overflow:hidden;border-width:0;display:inline-block;}</style>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script>
(function ($) {
var userId = "UID";
var accessToken = "Token";
var numDisplay = "9";
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: "https://api.instagram.com/v1/users/"+userId+"/media/recent/? access_token="+accessToken,
success: function(data) {
for (var i = 0; i < numDisplay; i++) {
var rand = Math.floor(Math.random()*10)+10+"%";
$(".insta-box").css('width', rand);
$(".insta").append("<div class='insta-box'><a target='_blank' href='"+data.data[i].link+"'>
<img class='instagram-image' src='" + data.data[i].images.low_resolution.url+"'width='auto'/><a></div>");
$(".insta").css('width', '100%');
}
}
});
})(jQuery);
</script>
【问题讨论】:
-
简答;是的你可以。给我们看一些代码......你尝试了什么,你在哪里卡住了?
-
@PeterVR 更新了初始帖子