0

正如标题所说:这行不通。该脚本确实移动了我想要移动的文章,如果我将选项放在选择器上,它也会对其进行动画处理,但它不会随机化元素的heightand 。width所有元素的随机宽度为 127px,我无法理解。提取脚本的提到的 php 文件如下:

更新:

    <script type="text/javascript" src="<? bloginfo('stylesheet_directory'); ?>/js/jquery.freetile.min.js"></script>
    <script>
    jQuery(document).ready(function() {

    for (i=0;i<40;i++) {
        var w = 128 * (parseInt(Math.random() * 3) + 1) - 1,h = 128 * (parseInt(Math.random() * 3) + 1) - 1;
    jQuery('article').width(w).height(h);
    }

        jQuery('#content').freetile();
         selector: 'article';
         animate: true;
         elementDelay: 10
        });
    </script>

这部分有什么问题吗?那会很奇怪,因为我从 github 存储库中复制并粘贴了它。

    for (i=0;i<40;i++) {
        var w = 128 * (parseInt(Math.random() * 3) + 1) - 1,h = 128 * (parseInt(Math.random() * 3) + 1) - 1;
    jQuery('article').width(w).height(h);
    }

这是文件的链接: https ://github.com/yconst/Freetile/blob/master/js/init.js

谢谢ComputerArts,我已经接受了你的回答:)

4

2 回答 2

1

随机化哪些元素的宽度和高度?你的问题可能是你没有传递任何东西jQuery()

// What are you trying to set the width/height of?
jQuery('').width(w).height(h)

可能应该是这样的

jQuery('#content .selector-for-tiled-divs').width(w).height(h)...
于 2012-09-24T17:14:59.980 回答
1

让我们解释一下你的代码

for (i=0;i<40;i++) {
    var w = 64 * (parseInt(Math.random() * 3) + 1) - 1,
    h = 48 * (parseInt(Math.random() * 3) + 1) - 1;

    //this part here is where the error happens.
    //you're asking to set the width and height to every element <content> on each iteration.
    //so on the last iteration, all the elements have the same width/height
    jQuery('content').width(w).height(h).appendTo('article');
}

我相信就是你想要的。

jQuery(document).ready(function() {
    for (i=0;i<40;i++) {
        var w = 64 * (parseInt(Math.random() * 3) + 1) - 1,
            h = 48 * (parseInt(Math.random() * 3) + 1) - 1;
        $('<div class="content" />').width(w).height(h).appendTo('body');
    }
});
于 2012-09-24T19:50:19.250 回答