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

Cart

jQuery and fancybox with click event

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #10121
    jona-jrgen
    Participant

    I just want to know if it is possible to create a fancybox, with the content of a hidden div, on a click event. Like this When button is pressed:

    <input type="button" class="headerButtonNormal" id="test" value="Contact information" onmouseover=this.className="headerButtonHoover"
               onmouseout=this.className="headerButtonNormal" onclick="showFormInformation()">
    

    Execute this javascript code and somehow generate a fancybox:

    function showFormInformation()
    {
    
    }
    

    And this is the div I want to show:

    <div id="inline">
    Test fancybox
    </div>
    

    While searching on the internet, it seemed like fancybox isnt made for this… it is more made for link klicking. Should I use a different framework???

    #10123
    andbdrew
    Participant

    This is right in Fancybox’s wheelhouse!

    just do:

    $.fancybox({
        content: $('#inline')
    })
    

    or as JFK pointed out:

    $.fancybox({
        href: '#inline'
    })
    

    you should note that the css path of your hidden div will be different once it is inside your fancybox.

    Check out this answer ( https://stackoverflow.com/a/3819374/599075 ) for another approach!

    #10122
    darshanags
    Participant

    Try:

    HTML:

    <input type="button" class="headerButtonNormal" id="test" value="Contact information"
    onmouseover=this.className="headerButtonHoover" onmouseout=this.className="headerButtonNormal">
    <div id="inline">Test fancybox</div>
    

    jQuery:

    $("#test").on("click", function () {
        showFormInformation();
    
        return false;
    });
    
    function showFormInformation() {
        $.fancybox({
            content: $("#inline").html()
        });
    }
    

    Fiddle here

    You might want to move your inline event handlers to be bound using jQuery since you are already using the library.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.