[jQuery] Use jquery before the DOM is ready?
I'm trying to have jquery set an image's opacity to 0. Then, while the image is fully loaded, it will fade the image in. It seems to work fine, unless the images have already been viewed in the browser and are stored in cache. In this case, the image is already loaded by the time of $(document).ready, then it fades out, then fades back in. I'm doing it like this: Code: $(document).ready(function() { $(#mainimage).animate({opacity: 0}, 0); }); $(window).load(function() { //when everything is finally loaded, fade image in $(#mainimage).animate({opacity: 1}, 1000); }); Am I just going about this the wrong way? Or is there a way to set the opacity to 0 before $(document).ready? Still somewhat new to jquery, so if I am making a stupid mistake, my bad. Any help would be great.
[jQuery] Re: Use jquery before the DOM is ready?
That works a lot better. Thanks for putting up with my questions hector. On Apr 4, 8:21 pm, Hector Virgen djvir...@gmail.com wrote: Actually, it might be better to just start off with 0 opacity and not mess with the visibility property at all: document.write('style type=text/css#mainimage{opacity:0}/style'); $(window).load(function() { //when everything is finally loaded, fade image in $(#mainimage).animate({opacity: 1}, 1000); }); -Hector On Sat, Apr 4, 2009 at 4:18 PM, Hector Virgen djvir...@gmail.com wrote: Try setting the opacity to 0 when you set it to visible. -Hector On Sat, Apr 4, 2009 at 4:15 PM, Derba ryancolantu...@gmail.com wrote: the css visible seems to make it visible before it has a chance to fade in, but I will tinker with it some to see if I can get it to work.
[jQuery] Re: Use jquery before the DOM is ready?
I tried the document.write method you told me to try, but using it anywhere causes the whole webpage to load up as a blank page. I have NO idea whats happening.
[jQuery] Re: Use jquery before the DOM is ready?
scratch that, including the document.write line in $(window).load (function() causes some error while leads to just a blank page in the browser. Using the first line of document.write('style type=text/ css#mainimage{visibility:hidden}/style'); seems to work fine thought. On Apr 4, 8:03 pm, Derba ryancolantu...@gmail.com wrote: I tried the document.write method you told me to try, but using it anywhere causes the whole webpage to load up as a blank page. I have NO idea whats happening.
[jQuery] Re: Use jquery before the DOM is ready?
the css visible seems to make it visible before it has a chance to fade in, but I will tinker with it some to see if I can get it to work.
[jQuery] Help with ajax contact form
I'm trying to use the ajax contact form i found from: http://capsizedesigns.com/blog/2008/04/an-ultra-slick-ajax-contact-form-with-jquery/ PHP: ?php error_reporting(E_NOTICE); function valid_email($str) { return ( ! preg_match(/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-] +)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix, $str)) ? FALSE : TRUE; } if($_POST['name']!='' $_POST['email']!='' valid_email($_POST['email'])==TRUE strlen($_POST['comment'])1) { $to = [EMAIL PROTECTED]; $headers = 'From: '.$_POST['email'].''. \r\n . 'Reply-To: '.$_POST['email'].'' . \r\n . 'X-Mailer: PHP/' . phpversion(); $subject = Contact Form; $message = htmlspecialchars($_POST['comment']); if(mail($to, $subject, $message, $headers)) { echo 1; //SUCCESS } else { echo 2; //FAILURE - server failure } } else { echo 3; //FAILURE - not valid email } ? And the js: $(document).ready(function(){ $('#myForm').ajaxForm(function(data) { if (data==1){ $('#success').fadeIn(slow); $('#myForm').resetForm(); } else if (data==2){ $('#badserver').fadeIn(slow); } else if (data==3) { $('#bademail').fadeIn(slow); } }); }); What I want it to do is still be usable when javascript is disabled. So I need to it output the actual error message though php instead of the number. I can obviously change this really easy by just putting the error message in the echo instead of there being the number. But when I try to change the javascript to match the corresponding error message, the whole script stops working. I try putting data==Please enter a valid email address. It seems to me that it should work, but I am still new to javascript and php so I could be making a stupid mistake. I would be grateful for any help.