Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add text to Fancy Box Loader

When clicking on a link I need to load a huge pdf on FancyBox overlay. Until the pdf is loaded I'm displaying a FancyBox loader. The problem is I need to add a text like "Please Wait...etc" in the FancyBox loader. Can any one help?

This is My Code:

    <p>
        <a class="fancypdf" href="hugepdf.pdf">Click
            Here To View The PDF</a>
    </p>

<script type="text/javascript">
    $(document).ready(function() {
        $(".fancypdf").click(function(event) {
            $.fancybox.open(this.href, {
                type : "iframe"
            });
            $.fancybox.showLoading();
            $("iframe.fancybox-iframe").load(function() {
                $.fancybox.hideLoading();
                content: {
                    text: 'Loading...',}
            });
            event.preventDefault();
        });
    });
</script>

P.S.

You can modify following fiddle.

DEMO

like image 465
Stef Avatar asked Aug 20 '14 11:08

Stef


People also ask

How do I open fancyBox on button click?

on('click', function() { $. fancybox(); }); });

What is fancyBox in HTML?

fancybox is designed to display images, video, iframes and any HTML content. For your convenience, there is a built in support for inline content and ajax. Images.


1 Answers

Please have a look at below modifications:

Updated Fiddle Link: http://jsfiddle.net/PudLq/619/

1) added CSS class as:

#fancybox-loading{
    background-repeat: no-repeat;
    background-position: center -108px;
    text-align: center;
}
#fancybox-loading div{
    margin: auto;
}
.overrideLoading{
    background: none !important;
    color: white;
    width: 92px !important;
}

2) after showing loading animation; altering the loading div HTML as per our need as follows:

$.fancybox.showLoading();
$('#fancybox-loading').append("<div class='overrideLoading'>Please Wait...</div>");

3) On hiding the animation; As suggested by "rockmandew" there is absolutely no need of reverting our HTML/CSS changes. On calling $.fancybox.showLoading() again directly; default loading animation will be shown to user. I have tested it and added one more link in fiddle to show default loading animation. Please click on "Show Default loading" to see that effect.

I hope this will help you.

like image 86
vijayP Avatar answered Oct 06 '22 06:10

vijayP