Jquery悬停弹出一个div

时间:2011-07-06 11:46:45

标签: jquery

我正在使用这个Jquery来弹出一个div

        <script type="text/javascript">


         $(function () {
        $('.bubbleInfo2').each(function () {
            var distance = 10;
            var time = 250;
            var hideDelay = 500;

            var hideDelayTimer = null;

            var beingShown = false;
            var shown = false;
            var trigger = $('.trigger2', this);
            var info = $('.popup2', this).css('opacity', 0);


            $([trigger.get(0), info.get(0)]).mouseover(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                if (beingShown || shown) {
                    // don't trigger the animation again
                    return;
                } else {
                    // reset position of info box
                    beingShown = true;

                    info.css({
                        top: 40,
                        left: -160,
                        display: 'block'
                    }).animate({
                        top: '-=' + distance + 'px',
                        opacity: 1
                    }, time, 'swing', function () {
                        beingShown = false;
                        shown = true;
                    });
                }

                return false;
            }).mouseout(function () {
                if (hideDelayTimer) clearTimeout(hideDelayTimer);
                hideDelayTimer = setTimeout(function () {
                    hideDelayTimer = null;
                    info.animate({
                        top: '-=' + distance + 'px',
                        opacity: 0
                    }, time, 'swing', function () {
                        shown = false;
                        info.css('display', 'none');
                    });

                }, hideDelay);

                return false;
            });
        });
    });

    //-->
       </script>

它运行良好,但我需要改变一种方式,以便能够在一个函数中调用它并传递参数,因为我在页面上使用它几次。在路上不要多次在它上面页

我会用类似的东西来称呼它:

            <script type="text/javascript">
    jQuery(function ($) {
        $(".bubbleInfo2").BubleFunction(....parameters to be passed

    });

</script>

2 个答案:

答案 0 :(得分:0)

<script type="text/javascript">

function callthisfunction() {
    $(".bubbleInfo2").BubleFunction(....parameters to be passed

}

答案 1 :(得分:0)

如果你想要,你需要制作jquery插件, 但很简单 查看 http://www.queness.com/post/112/a-really-simple-jquery-plugin-tutorial