Solved

In need of a simple onclick jquery crossfade script

Posted on 2010-08-16
11
944 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
  • 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 18

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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 18

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 18

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now