使用margin-attribute为mouseover / mouseout上的转换div设置动画

时间:2012-09-25 20:37:34

标签: jquery html jquery-animate

我想知道是否有人有办法解决我遇到的问题。我尝试了很多不同的代码,我从脚本和测试服务器中混合使用但是它们对我没有帮助,因为我想移动一个带有内部跨度的转换div,该内部跨度只能将文本稍微保留在加载位置的左对角线外,然后在悬停时移动到该站点,但仍然只有一个悬停,所以这个应该移出,同时用鼠标箭头离开热区。
我不知道如何在一个我可能在加载时调用的函数中组合类。我附上了我的CSS和HTML,以防任何人有问题。

我虽然想做一些事情,比如用左边的左边边缘移动它们,然后用边距向左边动画它们! -

这是我提出的jquery,但它没有做我想要的。它将物体向左/向右移动,而不是我希望它们移动到的角度对角线:

<script type="text/javascript">
        $(function() {
            $('#bgrclub .advantages').hover(
                function () {
                    var $this = $(this);
                    $this.stop().animate({'margin-left':'400px'},500);
                    $('#bgrclub .advantages',$this).stop(true,true).fadeOut(1500);

                },
                function () {
                    var $this = $(this);
                    $this.stop().animate({'margin-left':'95px'},1000);
                    $('#bgrclub .advantages',$this).stop(true,true).fadeIn();
                }
            );
        });


        </script>


    <div id="bgrclub">
    <div class="advantages"><span>A proper solution</span></div>
    <div class="advantages"><span>would have to work</span></div>
    <div class="advantages"><span>with differently</span></div>
    <div class="advantages"><span>long text spand</spa></div>
    <div class="advantages"><span style="padding-left:250px;">Random Text Span</span></div>
<div class="advantages"><span style="padding-left:435px;">A really, really, really long text span</span></div>
</div>

的CSS:

#bgrclub {background-image:url(../images/club_bgr.jpg);background-repeat:no-repeat;width:755px;height:544px;}
#bgrclub_bottompics {background-image:url(../images/club_bgr_bottompics.jpg); position:absolute; bottom:0px; left:0px;background-repeat:no-repeat;width:755px; height:95px; z-index:999;}
#bgrclub .advantages {position:relative;width:755px;float:left; padding-top:40px;-moz-transform:rotate(-20deg); /* Firefox 3.6 Firefox 4 */-webkit-transform:rotate(-20deg); /* Safari */-o-transform:rotate(-20deg); /* Opera */-ms-transform:rotate(-20deg); /* IE9 */transform:rotate(-20deg); /* W3C */}
#bgrclub .advantages span {font-family: 'Open Sans Condensed', sans-serif;font-size:175%; font-weight:lighter; color:#373737;padding:10px; padding-left:125px; margin-left:-150px; border-bottom-right-radius:10px; border-top-right-radius:20px; z-index:1000;
background: -moz-linear-gradient(left,  rgba(255,255,255,0) 0%, rgba(255,255,255,0) 23%, rgba(255,255,255,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,0)), color-stop(23%,rgba(255,255,255,0)), color-stop(100%,rgba(255,255,255,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(left,  rgba(255,255,255,0) 0%,rgba(255,255,255,0) 23%,rgba(255,255,255,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(left,  rgba(255,255,255,0) 0%,rgba(255,255,255,0) 23%,rgba(255,255,255,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(left,  rgba(255,255,255,0) 0%,rgba(255,255,255,0) 23%,rgba(255,255,255,1) 100%); /* IE10+ */
background: linear-gradient(to right,  rgba(255,255,255,0) 0%,rgba(255,255,255,0) 23%,rgba(255,255,255,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#ffffff',GradientType=1 ); /* IE6-9 */}

3 个答案:

答案 0 :(得分:1)

这是示例,您可以更改速度(500p)

$("#bgrclub").animate({

    right: '0'
    }, 500, function() {
    // Animation complete.
       $(this).css('margin-left', '300');
      /*
       *and you do many other thing here
      */
  });

答案 1 :(得分:1)

您可以将其定义为

$(document).ready(function () {
/**
* your code
*/
});

您可以更改悬停事件中的所有css属性:

$(#your_div).css('float', 'left');

$("#your_div").css('float', 'right');
$("#your_div").css('position', 'relative');

获取结果 等。

答案 2 :(得分:0)

人们,伙计们!我让它按照我想要的方式工作:

<!-- Hovering in the Advantages -->
        <script type="text/javascript">
            $(function() {
                $('#bgrclub .advantages span').hover(
                    function () {
                        var $this = $(this);
                        $this.stop().animate({'margin-left':'-10'},2000);
                        $('#.advantages',$this).stop(true,true).fadeOut(2500);

                    },
                    function () {
                        var $this = $(this);
                        $this.stop().animate({'margin-left':'-150px'},2000);
                        $('#.advantages',$this).stop(true,true).fadeIn();
                    }
                );
            });


        </script>