Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Preloader (CSS Spinner) and SSI script II

  1. #1
    Join Date
    Jul 2012
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Preloader (CSS Spinner) and SSI script II

    It takes a time, when I load a shop into an iFrame.
    I found some sweet CSS - spinners (on cssload.net) and I'm pondering how to display them.
    (Already spent 2 days with it :-))

    Options are:
    1. integrate CSS and Javascript into the mother page.
    2. into the loading page.

    In my case the mother page is quite fast loading. The shop: slower (2secs).
    It makes no sense to integrate the pre-loader spinner into the loading site, I tried that.
    So, in the article loading my iframe, we are.


    My problem:
    the spinner must stop spinning once the site has loaded and somehow he just don't get it, no matter what I try!
    Is it due to the SSI script code in the head?

    My code to stop the spinner spinning after the completed page load is:

    Code:
    var pre-loader=document.getElementById(“pre-loader”);
    window.addEventListener('load', function()
    {pre-loader.style.display = 'none';})
    or (tried both, makes no difference):

    Code:
    var overlay=document.getElementById(“pre-loader”);
    window.addEventListener('load', function()
    {pre-loader.style.display = 'none';})
    Why is it giving me the finger?
    Last edited by wol4; 09-03-2016 at 06:55 PM.

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I can't test anything from mobile but try without the dash in the variable name (you can't have dashes in JavaScript variables because it gets mistaken for a minus);
    Code:
    var preLoader=document.getElementById(“pre-loader”);
    window.addEventListener('load', function()
    {preLoader.style.display = 'none';})
    Or the correct variable name;
    Code:
    var overlay=document.getElementById(“pre-loader”);
    window.addEventListener('load', function()
    {overlay.style.display = 'none';})
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Jul 2012
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Doesn't work either, but thank you.
    I still need something to switch the spinner of once the shop has loaded into my iframe.

    I also tried:
    Code:
    $('#preloader').show();
    before and after
    Code:
    $('#preloader').hide();
    the content.

    Maybe I'm addressing the wrong page? The spinners markup sits before the iframe of course.
    I also tried to write it inside the SSI II script itself, but it stopped functioning after that :-)

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, I was just looking at your page, and there is no pre-loader and no preloader element. Not on the top page, nor on the first page one can load into the iframe.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jul 2012
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    I had a lil bug in my HTML in the article, just before the iframe. Sorry.
    I switched it on again. Normally the style is set to display: none;
    Ah, yes, pls click on "introductory titles" on the first menu button: this will load the iframe page.
    Last edited by wol4; 09-04-2016 at 04:08 PM.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, here's the problem - still no element with the id of preloader. There is however this (look very carefully at the quote marks):

    Code:
    <div id=“preloader” style="opacity: 0.7">
    Those are stylized leaning left and leaning right opening and closing double quotes, not the standard vertical double quotes, so the id is actually:

    “preloader”

    not:

    preloader

    Things will get much simpler if you correct the HTML markup to:

    Code:
    <div id="preloader" style="opacity: 0.7">
    Then, this should work:

    Code:
    var overlay=document.getElementById('preloader');
    window.addEventListener('load', function()
    {overlay.style.display = 'none';})
    Never use the left and right leaning single or double quotes in either HTML or javascript code unless you mean them as string literals.

    NOTEs: I see that you also made the same error in your javascript code:

    Code:
    var pre-loader=document.getElementById(pre-loader);
    window.addEventListener('load', function()
    {pre-loader.style.display = 'none';})
    So be sure to be careful there as well when fixing this.

    Also this (once fixed) will make the preloader disappear on load of the top page. After that, if you plan on bringing it back for the loading of each subsequent sub-page into the iframe, you will have to key off of the load event of the iframe or of its document for making it disappear again. But, since I have no firm indication you're even contemplating doing that yet. I'll leave the details of that till later, if needed.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Jul 2012
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the try, John :-)

    1. The thing in my HTML markup was the bug I had. I don't understand why you still saw it, but I have a long list of what I don't understand everyday, so ..
    2. I put the javascript (of your repaired version, only with "preloader" instead of pre-loader, because I've changed it's ID too) just before the SSI script in my theme.php (I tried also adding it in the body -- the same.)
    3. In my HTML markup, I set the style to: display: none; that's the idea.

    Preloader does not show.

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    So all fixed?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Jul 2012
    Posts
    24
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    No, the preloader does not show before the page loading.
    Quick-check yourself.

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You still have the same problem, and a new one. Here's the markup:

    HTML Code:
    <div id=“preloader” style="display: none; opacity: 0.7;">
    New problem - With it's display set to none right in the tag, it will never show unless you do something in javascript or overriding style to change that.

    Old problem - it's id still isn't preloader, you still have those messed up word processing quotes around it instead of valid HTML quotes delimiting the id.

    It should be:

    HTML Code:
    <div id="preloader" style="opacity: 0.7;">
    See the difference?

    On the plus side, your javascript:

    Code:
    var overlay=document.getElementById('preloader');
    window.addEventListener('load', function()
    {overlay.style.display = 'none';})
    No longer has that problem, however, I see an omission I missed before - the addEventListener function expects a third parameter (true or false):

    Code:
    var overlay=document.getElementById('preloader');
    window.addEventListener('load', function()
    {overlay.style.display = 'none';}, false);
    I'm not certain if that matters, but I've never seen it without that. Using false is usually fine and what is most customary. I believe it governs whether or not the event can 'bubble' (or in modern parlance 'propagate'), counterintuitively false means it can, which is normal and preferable as it allows other events of the same type on the same object/element to also fire.

    Further, even if everything else was right, you cannot set the variable overlay at that point because the element, even with the correct id hasn't been parsed yet. So do it like so:

    Code:
    window.addEventListener('load', function(){
    	var overlay = document.getElementById('preloader');
    	overlay.style.display = 'none';
    }, false);
    I'd just go direct at that point though:

    Code:
    window.addEventListener('load', function(){
    	document.getElementById('preloader').style.display = 'none';
    }, false);
    Either way, once the window loads the element will have been parsed, so everything should then be fine (assuming I understand what you're trying to do*).

    Good luck!


    *You do want it to show initially and then disappear when the page loads - right?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. how to display spinner buttons in another table
    By manleybruce in forum JavaScript
    Replies: 0
    Last Post: 12-06-2011, 09:37 AM
  2. spinner
    By thimmappa449 in forum JavaScript
    Replies: 1
    Last Post: 10-20-2010, 09:02 AM
  3. displaying a spinner for loading purpose
    By gargidas15 in forum Flash
    Replies: 1
    Last Post: 04-29-2009, 06:12 PM
  4. preloader script
    By bartjr in forum Looking for such a script or service
    Replies: 0
    Last Post: 02-10-2009, 12:07 AM
  5. DD Preloader Script
    By evilburn in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 12-15-2004, 04:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •