最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to just open a fancybox window (not onclick) - Stack Overflow

programmeradmin3浏览0评论

I am triggering the fancybox to open onclick like this:

$('.telefonosOtrosPaises').fancybox({
                    'type'          :   'iframe',
                    'href'          :   '.jsp',
                     'transitionIn' : 'elastic',
                    'transitionOut' : 'elastic',
                    /*'easingIn'      : 'easeInOutBack',

                    'easingOut'     : 'easeInOutBack',   */
                     /*onComplete : function(){ $('#fancybox-content').css({'height':'380px','width':'570px','background':'white','padding':'20px'})}*/
                     onComplete : function(){ $('#fancybox-content').css({'width':'630px','background':'white','paddingTop':'15px'})}
});

but how can i just open it in my js code when i need it?

I am triggering the fancybox to open onclick like this:

$('.telefonosOtrosPaises').fancybox({
                    'type'          :   'iframe',
                    'href'          :   'http://es.solmelia./nMenus/jsp/telefonosOtrosPaises.jsp',
                     'transitionIn' : 'elastic',
                    'transitionOut' : 'elastic',
                    /*'easingIn'      : 'easeInOutBack',

                    'easingOut'     : 'easeInOutBack',   */
                     /*onComplete : function(){ $('#fancybox-content').css({'height':'380px','width':'570px','background':'white','padding':'20px'})}*/
                     onComplete : function(){ $('#fancybox-content').css({'width':'630px','background':'white','paddingTop':'15px'})}
});

but how can i just open it in my js code when i need it?

Share Improve this question edited Dec 21, 2011 at 12:39 meo 31.2k19 gold badges89 silver badges123 bronze badges asked Dec 21, 2011 at 12:31 Toni Michel CaubetToni Michel Caubet 20.2k58 gold badges217 silver badges387 bronze badges 2
  • See: fancyapps./fancybox/#docs – Zirak Commented Dec 21, 2011 at 12:35
  • 1 could you go into your profile and Mark some Answers to your previous questions as right please. – meo Commented Dec 21, 2011 at 12:36
Add a ment  | 

5 Answers 5

Reset to default 7

Instead of calling .fancybox on an element, call it like this:

$.fancybox.open(...)

Note this is fancybox 2 syntax, although it might work with v1

If you want to have it open on both onclick and when prompted in your code, just call click on the element you've attached it to.

$('.telefonosOtrosPaises').click();

you can just call yourControl.click() to simulate a click event.

That way you can call it whenever you want it :)

According to Fancybox's blog, you can try something like this:

$.fancybox(
    $('.telefonosOtrosPaises'), 
    {
        'type'          :   'iframe',
        'href'          :   'http://es.solmelia./nMenus/jsp/telefonosOtrosPaises.jsp',
         'transitionIn' : 'elastic',
        'transitionOut' : 'elastic',
        /*'easingIn'      : 'easeInOutBack',

        'easingOut'     : 'easeInOutBack',   */
         /*onComplete : function(){ $('#fancybox-content').css({'height':'380px','width':'570px','background':'white','padding':'20px'})}*/
         onComplete : function(){ $('#fancybox-content').css({'width':'630px','background':'white','paddingTop':'15px'})}
    }
);

This can be done very easily:

   <div id="divFancy" style="display: none;">
         FANCY BOX CONTENT GOES HERE
   </div>

    <script  type="text/javascript">
        $(document).ready(function () {
            $.fancybox({
                'href': '#divFancy'
            });
        });
    </script>
<html>
<head>
<script src="http://ajax.googleapis./ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>

<script type="text/javascript">
$(document).ready(function() {
    $('#target').click(function() {  
        $('.telefonosOtrosPaises').fancybox({
                        'type'          :   'iframe',
                        'href'          :   'http://es.solmelia./nMenus/jsp/telefonosOtrosPaises.jsp',
                         'transitionIn' : 'elastic',
                        'transitionOut' : 'elastic',
                        /*'easingIn'      : 'easeInOutBack',

                        'easingOut'     : 'easeInOutBack',   */
                         /*onComplete : function(){ $('#fancybox-content').css({'height':'380px','width':'570px','background':'white','padding':'20px'})}*/
                         onComplete : function(){ $('#fancybox-content').css({'width':'630px','background':'white','paddingTop':'15px'})}
        });
    });
});
</script>

<input type="button" id="target" value="press me"/>
</body>
</html>
发布评论

评论列表(0)

  1. 暂无评论