Results 1 to 10 of 10

Thread: Dynamically changing background images works locally, but intermittent online.

  1. #1
    Join Date
    Oct 2012

    Dynamically changing background images works locally, but intermittent online.

    Hi, I have a problem with changing background images.
    This code works perfectly running it local but seems to work when it wants to coming from the server.
    Anyone know why, and how to fix it?

    var images = ['reddoor.jpg', 'oldwindow2.jpg', 'stainedglass.jpg', 'bluestripe.jpg', 'cueball3.jpg', 'bodyimage.jpg', 'redbody.jpg', 'oldwindow1.jpg', 'nighttime.jpg' ];
    function getBackground(){
            var random = Math.floor(Math.random() * images.length);
            var imgurl = images[random];
            document.body.style.backgroundImage = 'url(' + imgurl + ')';


  2. #2
    Join Date
    Mar 2007
    First and obvious issue is image data size.

    How big are the images in filesize?
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Oct 2012
    Small images that will be tiled in the body background, none over 20kb.
    I would rather just have the images display in order of the array than random but I can't make that work either, the last image in the array always comes up. I've tried js and jquery and different methods but always get the last image. What is up with that?

  4. #4
    Join Date
    Mar 2009
    What does the rest of your code look like? What calls the "getBackground" function?

  5. #5
    Looks to me like you're trying to do something client side that has no business being done in client side scripting.

    Might I ask why you aren't doing this on the server in something like PHP? You could even store the 'last' image in a session.

    Though are you 100% sure the images are in the same directory as where the script is running? I know that's the obvious thing, but I have to ask.

  6. #6
    Join Date
    Oct 2012
    Trying to give a choice of background images from a button click.
    All of the code is above, except for the button
    It displays a random image right now (onclick)
    But sometimes shows a blank screen, a lot.
    <input id="background" type="button"  value="Random Background" style="position: absolute;right:0px;top:0px;">
    I would much rather display each image from the array in order than random.

    The click function is loaded in (function ready).
    It's not imperative but would be nicer if it worked right.
    If you want to see it... whatarethelotterynumbers.org
    Last edited by Baldy; 06-27-2014 at 06:55 PM.

  7. #7
    Well, you have images that don't exist in that live copy:

    etc, etc... whole slew of them 404.

    Silly question, you say it works local? Are you sure the filenames are all lower-case? If you're on windows locally it's case insensitive, most servers are case sensitive so if you use all lower-case names in the script, they MUST be all lower-case on the server.

    Side note -- gah that markup... yikes.

  8. #8
    Join Date
    Oct 2012
    All of the images load, just not all the time (only locally). Can't figure out why the images aren't showing up online with the image in the URL, they are all there and do work intermittently. Both of the images you listed are in there and do show up.
    I know my code messy but it works (mostly), I'm not a coder, just wanted to make my own site.

  9. #9
    Join Date
    Mar 2007
    You would preload the images in background first. Google preloading of images in background and you will find plenty of examples.

    20kb is not a vastly huge file size, If your images are not loading properly when you are loading up the page from the server, you have a bottle neck somewhere, this could be in your home, especially if you are using a WiFi connections and you have other members of the family using WiFi, your router could also be a cause of delay, not enough down stream bandwidth, your router tries to share among users a limited amount of bandwidth. A typical 100Mb line would have a ratio of 60:40 which would mean that your connection would give you 60% of the bandwidth with a 40% headroom for collisions, drops and corrupt data and requests for resending, if you have two people on the same line this plummets further because you will then have two lots of downstream / headroom factors.

    If the bottleneck is in your ISP's line, the bRouter, then the contention ratio may be high as they may be stacking you all in the hopes that you are not all online at the same time, this is felt in download speed drops, I suggest you do random broadband speed tests and not time and speed and plot it on a graph to see if a pattern is forming, you could have someone file sharing. Often a complaint about the speed of your service and pointing out that you are not getting the speed that you are promised in the contract, claiming that they are running a high contention ratio for users on the node you are on will often provoke a settings change and they can give your IP address a higher priority.

    If none of the service is showing up as the problem then the only answer is the server host you are using, likely they are over subscribed and if you are on a shared server, if you have someone that is running a demanding service, that will impact on delivery of your site and data. It takes a complaint to them to get them to investigate why your server service is very slow.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  10. #10
    Join Date
    Oct 2012
    Thanks for your help.
    I just re-upped my subscription for two years more hosting and troubles started, not big ones but seems funny right after I paid them.
    Thanks again, I'll see what I can do.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12740 seconds
  • Memory Usage 2,946KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (10)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates