Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

In need of a simple onclick jquery crossfade script

Posted on 2010-08-16
11
Medium Priority
?
970 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
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

 
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
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)
Suggested Courses

609 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