将属性对象传递给jQuery动画函数

时间:2016-02-20 17:27:06

标签: javascript jquery object parameters jquery-animate

我有这段代码:

       <!-- Item -->
        <article class="one-half">
            <figure class="one-half heightfix"><a href="spalare-corp-exterior-nava.html"><img src="/imagini/spalare.jpg" alt="destination" /></a></figure>
            <div class="one-half heightfix">
                <div class="text">
                    <h3><a href="spalare-corp-exterior-nava.html">Spalare corp exterior nava</a></h3>
                    <p>Executam lucrari de spalare cu apa dulce inalta presiune corp exterior nava. Totodata efectuam lucrari de hidrosablare la cererea clientului.</p>
                    <a href="spalare-corp-exterior-nava.html" class="more" title="Read more">Mai multe</a>
                </div>
            </div>
        </article>
        <!-- //Item -->

我想将enlarge_obj和shrink_obj传递给jQuery动画函数。

但它没有用。

如果我写这样的代码:

var delta = _window.width() / 30, // resize hexagons by delta px
window_height = _window.height(); // .box-1/window height

 $('.hexagon').each(function () { // get animated boxes
    var $this = $(this),
        width_1 = $this.width(),
        height_1 = $this.height(),
        multi = 0, // adjust resize to scroll speed (depends on delta)
        ratio = 1.167; // to calculate height

    // animation properties
    var enlarge_obj = {
            width: function() {return width_1 += (delta * multi)},
            height: function() {return width_1 * ratio}
        },
        shrink_obj = {
            width: function() {return width_1 -= (delta * multi)},
            height: function() {return width_1 * ratio}
        };


        ....


        function scrollHandler() {
            ...
            $this.animate(enlarge_obj, 0, 'linear');
            ...
            $this.animate(shrink_obj, 0, 'linear');
        }
}

它工作正常。 我究竟做错了什么? THX。

0 个答案:

没有答案