Solved

In need of a simple onclick jquery crossfade script

Posted on 2010-08-16
11
940 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
Comment Utility
               $('#old_image').fadeOut(100, function(){
                        $('#new_image').fadeIn(100);                                          
                });
0
 
LVL 18

Author Comment

by:Greg Alexander
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ooops, sorry leakim971! I barely glanced at your answer and thought it was some other plugin.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 18

Author Comment

by:Greg Alexander
Comment Utility
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
Comment Utility
no worries @JF0
Please continue to assist @galexander07
0
 
LVL 16

Accepted Solution

by:
JF0 earned 250 total points
Comment Utility
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
Comment Utility
Perfect! Thanks so much.
0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
Thanks for the points!
0
 
LVL 16

Expert Comment

by:JF0
Comment Utility
Happy to help
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
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 …
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…

762 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

12 Experts available now in Live!

Get 1:1 Help Now