TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-04-2009, 05:03 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Timebased event

Hi.

I have a header image I want to switch between several images by calling a PHP-script.

Currently I have it changing image when clicking on the header-element(just to test that it actually works).

HTML Code:
	<?php echo link_js('static/js/HeaderChanger.js'); ?>
</head>
<body>

	<div id="container">

		<div id="header">

			<div id="head"><img src="<?php echo $this->gallery->getRandom(); ?>" height="200" /></div>
			<div id="logo"><img src="static/img/logo.jpg" /></div>

		</div>
javascript Code:
$(document).ready(function(){

   
    $("#head").click(function() {
   
        $("#head").load("HeaderChanger.php");
   
    });
   
 });

php Code:
<?php


    include('includes/config.php');
   
?>

    <img src="<?php echo $gallery->getRandom(); ?>" height="200" />

This works great, it changes header when I click on it.
However I want this to be timebased and not clickbased. I want it to change automatically every x seconds.

Also it would be cool to have it transitioned like the first image is faded out, and the new one is faded in.

How would I do that?
I'm using jQuery btw.
__________________
Tanax is offline  
Reply With Quote
Old 10-04-2009, 06:08 PM   #2 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

javascript Code:
$(document).ready(function() {

  // This will hold our timer
  var myTimer = {};

    // Set the timer for 2 seconds
    myTimer = $.timer(2000, function(){

      // Load the new image.
      $("#head").load("HeaderChanger.php");

   });

});

I'm giving credit to ETbyrne for his jQuery Timer Plugin. Just change the "2000"(ms) to how ever long you want the delay to last.

Attached you will find the zip file that contains the entire plugin distribution. VirusTotal Scan
Attached Files
File Type: zip jquery-timer.zip (20.5 KB, 8 views)
__________________
My Site
adamdecaf is offline  
Reply With Quote
The Following User Says Thank You to adamdecaf For This Useful Post:
Tanax (10-04-2009)
Old 10-04-2009, 07:58 PM   #3 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Thanks, that worked quite well.
However, it doesn't work exactly how I want it to.

You see, that only changes the header once. I want it to change every x seconds.
I tried to make a hack for it like this:
javascript Code:
$(document).ready(function() {

    function myfunction()
    {
       
        // This will hold our timer
        var myTimer = {};
       
        myTimer = $.timer(2000, function(){

            // Load the new image.
            $("#head").load("HeaderChanger.php");

        });
   
    }
   
    while(true)
    {
   
        setTimeout("myfunction()", 2000);
   
    }

});

however that only seems to work twice because it changes 2 times after the page loaded. Then it doesn't change anymore..
Any ideas?
__________________
Tanax is offline  
Reply With Quote
Old 10-04-2009, 08:05 PM   #4 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

Add myfunction() after you load the new image:

Code:
$(document).ready(function() {

    function myfunction()
    {
        
        // This will hold our timer
        var myTimer = {};
        
        myTimer = $.timer(2000, function(){

            // Load the new image.
            $("#head").load("HeaderChanger.php");

            myfunction();

        });
    
    }
    
    while(true)
    {
    
        setTimeout(myfunction(), 2000);
    
    }

});
Also, for this particular application you may want to consider using the more simple Delay Plugin.

Btw how do you do the javascript code coloring?
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 10-04-2009, 08:14 PM   #5 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Did like this actually, but your point worked.
javascript Code:
$(document).ready(function() {

    var time = 7000;

    function myfunction()
    {
   
        // This will hold our timer
        var myTimer = {};
           
        myTimer = $.timer(time, function(){

            // Load the new image.
            $("#head").load("HeaderChanger.php");
           
            myfunction();

        });
       
    }
   
    myfunction();

});

Oh, and you use highlight=javascript but in [] and then /highlight within [].

Now I'm just wondering how to do a fading transition between the images when it's loading a new image?
__________________
Tanax is offline  
Reply With Quote
Old 10-04-2009, 08:24 PM   #6 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

To do fading would require that you somehow load the image into a hidden element which would then gradually appear over the old image. When the new image is then in place remove the element containing the old image.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Old 10-05-2009, 09:14 PM   #7 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by ETbyrne View Post
To do fading would require that you somehow load the image into a hidden element which would then gradually appear over the old image. When the new image is then in place remove the element containing the old image.
Or you load an animated .gif file followed (timed) by the second image.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Old 10-06-2009, 01:05 PM   #8 (permalink)
how quixotic are you?
 
ETbyrne's Avatar
 
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
ETbyrne is on a distinguished road
Default

That would definitely be less technical, but the effect would probably be less crisp.
__________________
Dingo Web Systems > http://www.dingocode.com
My Website > http://www.evanbot.com
ETbyrne is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Event to PHP Calendar buildakicker General 21 01-29-2013 12:01 PM
Event Scheduler... Maybe? Gurnk Advanced PHP Programming 4 02-14-2008 08:03 PM


All times are GMT. The time now is 10:39 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design