[Special Summer Sale] 40% OFF All Magento 2 Themes

Cart

Triggering FancyBox from a DIV onclick();

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #10129
    haroldo
    Participant

    a) you can put other items inside an a tag, it will work but it’s unsemantic.

    b)

    1. put your iframe in a hidden div (or ajax it in on click)
    2. the do $(‘.menuitem’).click(hiddendiv.fancyb…().show())

    Personally i would always avoid using onclick=”” it’s much easier to maintain your code in an external js file

    #10127
    tim
    Participant

    This question seems to have been asked a lot, but I haven’t seen an answer that works.

    So I have a div that works like this:

    <div onclick="location.href='http://www.abc123.com';" class="menuitem">
    </div>
    

    Now I need the link (specified in location.href) to open up in a fancybox iframe.

    I would love to use an A element but this Div holds other items so I don’t think I can.

    I am open to all suggestions… even using elements other than divs, or using a different jquery iframe lightbox.

    Thanks

    Tim Mohr

    #10128
    pythonian29033
    Participant

    I was doing the same thing and wanted to invoke fancybox dynamically also
    I know it might not be ideal, but this is what i did (I use jquery btw):

    JS:

    jQuery(document).ready(function($){
        $(".fancybox").fancybox();
        $("form").submit(function(){
            $(".fancybox").trigger("click");
            return false;
        });
    });
    

    HTML:

    <a href="#div_id" class="fancybox"></a>
    <div style="display:none;">
         <div id="div_id">
             This will show up in my fancybox
         </div>
    </div>
    

    it’s a quicker easier way; I found, hope it helps someone!
    happy coding!

    #10130
    ronald
    Participant

    This demonstrates how to use fancybox without requiring the <a href> link element.

    Inline (1.3.4):

    <div id="menuitem" class="menuitem"></div>
    
    <div style="display:none;">
        <div id="dialogContent">
        </div>
    </div>
    
    $('#menuitem').click(function() {
        $.fancybox({
            'type': 'inline',
            'content': '#dialogContent'
        });
    });
    

    Inline (2.1.5):

    <div id="menuitem" class="menuitem"></div>
    
    <div style="display:none;">
        <div id="dialogContent">
        </div>
    </div>
    
    $('#menuitem').click(function() {
        $.fancybox({
            'type': 'inline',
            'href': '#dialogContent'
        });
    });
    

    Iframe:

    <div id="menuitem" class="menuitem"></div>
    
    $('#menuitem').click(function () {
        $.fancybox({
            type: 'iframe',
            href: 'http://www.abc123.com'
        });
    });
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.