www.webdeveloper.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 35

Thread: How to Loop Images in a webpage with an even delay?

  1. #16
    Join Date
    Feb 2009
    Posts
    2

    Angry I need to repositioning a javascript slideshow using css?

    Hi,

    I am a total Newbie to javascript and I have been trying for 5 hrs now to use CSS to reposition the slideshow see code below, and it won't work.

    Can anybody help?


    This is my Javascript in HTML
    <div id="slideshow">
    <script type="text/javascript">
    var pictureArchive= ['1.jpg','2.jpg','3.jpg','4.jpg'];
    window.onload=function() {
    var o=document.createElement('img');
    o.setAttribute('id', 'image');
    o.setAttribute('src', pictureArchive[0]);
    o.setAttribute('alt', '');
    document.body.appendChild(o);
    rotate(pictureArchive.length);
    left=400;
    }
    function rotate(idx) {
    if(idx>=pictureArchive.length) {
    idx=0;
    }
    document.getElementById('image').src=pictureArchive[idx++];
    timerID=setTimeout('rotate('+idx+')', 4000);
    }
    </script>

    </div>

    This is my CSS
    #slideshow{
    width:375px;
    height:332px;
    position:absolute;
    top:35px;
    left:363px;

    }

  2. #17
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    o.setAttribute('alt', '');
    document.getElementById('slideshow').appendChild(o);
    rotate(pictureArchive.length);
    left=400; // this does nothing and will never be reached
    Last edited by Fang; 02-24-2009 at 05:01 PM.
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #18
    Join Date
    Feb 2009
    Posts
    2

    Smile Thank you Fang I owe you a pint

    I can't thank you enough .

    Its worked , its worked - cheers!

  4. #19
    Join Date
    Mar 2010
    Posts
    4

    Positioning the Image Output

    How can I control the position where the output will be displayed by the function below? For example, I want to display the picture output between two paragraphs.

    <H1>this is the bottom page</H1>

    <script type="text/javascript">
    window.onload=function display_pics() {
    var o=document.createElement('img');
    o.setAttribute('id', 'image');
    o.setAttribute('src', pictureArchive[0]);
    alert (pictureArchive[0].src);
    o.setAttribute('alt', '');
    document.body.appendChild(o);
    rotate(pictureArchive.length);
    }
    </script>
    <H1>this is the bottom page</H1>

  5. #20
    Join Date
    Mar 2010
    Posts
    4
    How can you attach an href link to each image that is looped?

  6. #21
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    o.onclick= function(){doSomething();};
    At least 98% of internet users' DNA is identical to that of chimpanzees

  7. #22
    Join Date
    Mar 2010
    Posts
    4

    Images with Redirected HREFs

    I created 2 arrays for the href links
    var pictureArchive= ['1.jpg','2.jpg','3.jpg','4.jpg'];
    var hrefArchive= ['http://1.com','http://2.com','http://3.com','http://4.com'];

    how would I incorporate the array to the function rotate(idx) and window.onload=function() ?

    Can you also suggest a site with good tutorial on using "document.getElementById"?

  8. #23
    Join Date
    Mar 2010
    Posts
    4
    Thank you Fang, I was able to get the href links working already. I added urllink=hrefArchive[idx]; to function rotate(idx) and then used the
    o.onclick= function() to open urllink.

  9. #24
    Join Date
    Nov 2010
    Posts
    6
    I have the following script taken from this thread to loop through 4 images:


    <script type="text/javascript">
    var pictureArchive= ['1.jpg','2.jpg','3.jpg','4.jpg'];

    window.onload=function() {
    var o=document.createElement('img');
    o.setAttribute('id', 'image');
    o.setAttribute('src', pictureArchive[0]);
    o.setAttribute('alt', '');
    document.body.appendChild(o);
    rotate(pictureArchive.length);
    }

    function rotate(idx) {
    if(idx>=pictureArchive.length) {
    idx=0;
    }
    document.getElementById('image').src=pictureArchive[idx++];
    timerID=setTimeout('rotate('+idx+')', 5000);
    }
    </script>

    All well and good, but can somebody please guide me how I can display these images in a table background?

    e.g. <table border="0" height="311" width="873" cellspacing="0" cellpadding="0" background="image">

    Any help would be greatly appreciated.

  10. #25
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    var pictureArchive= ['1.jpg','2.jpg','3.jpg','4.jpg'];
    
    window.onload=function() {
    rotate(pictureArchive.length);
    }
    
    function rotate(idx) {
    if(idx>=pictureArchive.length) {
    idx=0;
    }
    document.getElementsByTagName('table')[0].style.backgroundImage = 'url('+pictureArchive[idx++]+')';
    timerID=setTimeout(function(){rotate(idx)}, 5000);
    }
    At least 98% of internet users' DNA is identical to that of chimpanzees

  11. #26
    Join Date
    Nov 2010
    Posts
    6
    Quote Originally Posted by Fang View Post
    Code:
    var pictureArchive= ['1.jpg','2.jpg','3.jpg','4.jpg'];
    
    window.onload=function() {
    rotate(pictureArchive.length);
    }
    
    function rotate(idx) {
    if(idx>=pictureArchive.length) {
    idx=0;
    }
    document.getElementsByTagName('table')[0].style.backgroundImage = 'url('+pictureArchive[idx++]+')';
    timerID=setTimeout(function(){rotate(idx)}, 5000);
    }
    Thanks for the quick reply Fang! My coding knowledge is next to zero with at best a rudimentary knowledge of HTML... I'm more into networking and that stuff.

    If I have the following normal HTML table code, where do I insert the code for the background change please?


    <table width=500>
    <tr>
    <td>Hello world!</td>
    </tr>
    </table>

  12. #27
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    
    <script type="text/javascript">
    var pictureArchive= ['1.jpg','2.jpg','3.jpg','4.jpg'];
    
    window.onload=function() {
    rotate(pictureArchive.length);
    }
    
    function rotate(idx) {
    if(idx>=pictureArchive.length) {
    idx=0;
    }
    document.getElementsByTagName('table')[0].style.backgroundImage = 'url('+pictureArchive[idx++]+')';
    timerID=setTimeout(function(){rotate(idx)}, 5000);
    }</script>
    
    <style type="text/css">
    * {margin:0;padding:0;}
    </style>
    
    </head>
    <body>
    <table width=500>
    <tr>
    <td>Hello world!</td>
    </tr>
    </table> 
    </body>
    </html>
    At least 98% of internet users' DNA is identical to that of chimpanzees

  13. #28
    Join Date
    Nov 2010
    Posts
    6
    Quote Originally Posted by Fang View Post
    Code:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    
    <script type="text/javascript">
    var pictureArchive= ['1.jpg','2.jpg','3.jpg','4.jpg'];
    
    window.onload=function() {
    rotate(pictureArchive.length);
    }
    
    function rotate(idx) {
    if(idx>=pictureArchive.length) {
    idx=0;
    }
    document.getElementsByTagName('table')[0].style.backgroundImage = 'url('+pictureArchive[idx++]+')';
    timerID=setTimeout(function(){rotate(idx)}, 5000);
    }</script>
    
    <style type="text/css">
    * {margin:0;padding:0;}
    </style>
    
    </head>
    <body>
    <table width=500>
    <tr>
    <td>Hello world!</td>
    </tr>
    </table> 
    </body>
    </html>

    Thanks a lot Fang. If you're ever in Malta let me know and I'll buy you a pint or 2 or 9.

  14. #29
    Join Date
    Nov 2010
    Posts
    6
    Still running into problems with it Fang.

    The code itself works, but it's affecting all my tables in the page. How can I get it to change the background of only one specific table?


    mbusu

  15. #30
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Reference the table by id, document.getElementById('tableID')

    http://www.hotdesign.com/seybold/
    At least 98% of internet users' DNA is identical to that of chimpanzees

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.15329 seconds
  • Memory Usage 3,017KB
  • Queries Executed 15 (?)
More Information
Template Usage (37):
  • (1)SHOWTHREAD
  • (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
  • (6)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (15)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (15)postbit
  • (15)postbit_onlinestatus
  • (15)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 (74):
  • 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
  • pagenav_page
  • pagenav_complete
  • 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