Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use fancybox using onclick?

I am trying to make use of JQuery and Fancybox. This is how it should be used: http://fancy.klade.lv/howto

However, I can not generate many ids for "a href" and I do not want to make many instances of fancybox ready. So I want to be able to use one fancy box instance for many hyperlinks that do the same thing.

Whenever any of these links are clicked, the fancybox should popup for it. I thought I would use the onclick attribute for a "<a href" tag or any other tags, I can chnage this but how do I use the fancybox? I tried this but nothing came up:

<a href="#not-working" onclick="fancybox(hideOnContentClick);">Not Working?</a>

Thanks for any help

like image 787
Abs Avatar asked May 16 '09 21:05

Abs


People also ask

How do I open fancyBox on button click?

jQuery(document). ready(function($) { $('button'). on('click', function() { $. fancybox(); }); });

What is fancyBox in Javascript?

Fancybox saves you time and helps to easily create beautiful, modern overlay windows containing images, iframes, videos or any kind of HTML content. This is the 4th generation of Fancybox and brings lots of fresh features.

What is fancyBox in HTML?

fancybox can be used to display any HTML element on the page. First, create a hidden element with unique ID: <div style="display: none;" id="hidden-content"> <h2>Hello</h2> <p>You are awesome.</p> </div>


2 Answers

Don't do it that way. If you can't generate unique IDs (or simply don't want to) you should be doing it with CSS classes instead:

<a href="image.jpg" class="fancy"><img src="image_thumbnail.jpg"></a>

with:

$(function() {
  $("a.fancy").fancybox({
    'zoomSpeedIn': 300,
    'zoomSpeedOut': 300,
    'overlayShow': false
  }); 
});

(from their usage page).

like image 126
cletus Avatar answered Sep 23 '22 10:09

cletus


This demonstrates how to use fancybox (1.3.4) without requiring the <a href> link element by calling fancybox directly.

Inline:

<div id="menuitem" class="menuitems"></div>

<div style="display:none;">
    <div id="dialogContent">
    </div>
</div>

$('.menuitems').click(function() {
    $.fancybox({
        type: 'inline',
        content: '#dialogContent'
    });
});

Iframe:

<div id="menuitem" class="menuitems"></div>

$('.menuitems').click(function () {
    $.fancybox({
        type: 'iframe',
        href: 'http://www.abc123.com'
    });
});
like image 22
Ronald Avatar answered Sep 24 '22 10:09

Ronald