Solved

In need of a simple onclick jquery crossfade script

Posted on 2010-08-16
11
962 Views
Last Modified: 2012-05-10
I need a simple onclick fade image to another, concept might look like this

function crossFade(new_image){
      $("#old_image").crossFade('new_image');      
}


I know corssFade is not a jquery function, but should be! Basically I would need a function that I could fade one #main image to another src and do it in a cross fade manner. Any ideas?

0
Comment
Question by:Greg Alexander
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 92

Expert Comment

by:objects
ID: 33451612
               $('#old_image').fadeOut(100, function(){
                        $('#new_image').fadeIn(100);                                          
                });
0
 
LVL 19

Author Comment

by:Greg Alexander
ID: 33451637
Close, Here is what I have

<script>
$(document).ready(function(){
      $(".changeto").click(function(){
            $('#main').fadeOut(100, function(){
                  $("#main").attr('src',$(this).attr('hover'));
                  $('#main').fadeIn(100);                                          
            });
      });
});
</script>





I basically have 5 small images underneath a larger image that when I click on one, I need to pass the attr hover (which is the path to the new image) to the #main and make it a fade. The above codes issue obviously is that there is a complete fade out then an attribute switch then a complete fade in, which is not what I want. Any more ideas?
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 33454952
I think it's not really your answer but you may use this plugin : http://malsup.com/jquery/cycle/int2.html

With : $("#s1").cycle({"fx":"fade","timeout":0,"next":"#s1"});

test page :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("#s1").cycle({"fx":"fade", "timeout":0, "next":"#s1"});
	});
</script>
</head>
<body>
<div id="s1"> 
    <img src="http://www.bodyboardpro.net/actualite/Photos/zicatelapro2010_2.jpg">
    <img src="http://www.bodyboardpro.net/actualite/Photos/zicatelapro2010_1.jpg">
</div>
</body>
</html>

Open in new window

0
Stressed Out?

Watch some penguins on the livecam!

 
LVL 16

Expert Comment

by:JF0
ID: 33469405
I've pretty much stopped writing my own image faders/sliders and have started using this plugin that is super easy to use and includes many different effects.

http://jquery.malsup.com/cycle/
0
 
LVL 16

Expert Comment

by:JF0
ID: 33469414
Ooops, sorry leakim971! I barely glanced at your answer and thought it was some other plugin.
0
 
LVL 19

Author Comment

by:Greg Alexander
ID: 33469973
I would like to be able to use the plugin, I have modified it to use it, but I have one problem, I want it to fade to a specific item instead of newt, so:









Say, img 1 is showing, when I click it, it advances to the next one in the list, is there a way I can specify which item it would fade to usinmg cycle? Basically I have smaller thumbnails and I would like it to change to a larger image of the one I click on Attached is an example.


show.gif
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33469998
no worries @JF0
Please continue to assist @galexander07
0
 
LVL 16

Accepted Solution

by:
JF0 earned 250 total points
ID: 33470031
Does this demo do what you are asking for?

http://jquery.malsup.com/cycle/pager3.html 
0
 
LVL 19

Author Closing Comment

by:Greg Alexander
ID: 33470061
Perfect! Thanks so much.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33470076
Thanks for the points!
0
 
LVL 16

Expert Comment

by:JF0
ID: 33470091
Happy to help
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question