?
Solved

In need of a simple onclick jquery crossfade script

Posted on 2010-08-16
11
Medium Priority
?
967 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 1000 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
How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

 
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 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to dynamically set the form action using jQuery.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

800 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