2

I am creating an image slider in JavaScript and i want to add effects like fadeIn and fadeOut without jQuery.

html:

<body>
<img src="images/1.jpg" alt=""  id="slide" width="700px" height="340px" > 
 </body>

JavaScript:

var slideshow = new Array();

slideshow[0] = new Image();
slideshow[0].src= "images/1.jpg";

slideshow[1] = new Image();
slideshow[1].src= "images/2.jpg";

slideshow[2] = new Image();
slideshow[2].src= "images/3.jpg";


var inc = 0;

function slide(){
document.getElementById('slide').src = slideshow[inc].src;
if(inc<2)
inc++;
else
inc = 0;
setTimeout("slide()",2000);
}
slide();
4
  • Why don't you want to use jquery? Commented May 15, 2015 at 21:51
  • How do you feel about css? (css3) Commented May 15, 2015 at 21:53
  • 1
    Have you looked here: stackoverflow.com/questions/13733912/… or here: jsfiddle.net/gabrieleromanato/cMp7s Commented May 15, 2015 at 21:54
  • If i use css animation then it will not work in some browsers. Commented May 15, 2015 at 21:54

1 Answer 1

1

You can't do it with Javascript alone because CSS controls opacity for fading. But there is your clue. Use javascript to control the opacity of the image since, in your comment, you said you don't want to use CSS animation properties and opacity should work in every browser.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.