Cool Guy Yo
Cool Guy Yo

Reputation: 6120

How do I change add a opacity to an animate function in jquery

I have the following code which I got from http://css-tricks.com/startstop-slider/ I would like to switch the animate property from a top animate on the img to just a opacity fade in fade out. How would I go about doing so with the following code.

// SET THIS VARIABLE FOR DELAY, 1000 = 1 SECOND
var delayLength = 5000;

function doMove(panelWidth, tooFar) {
 var leftValue = $("#mover").css("left");

 // Fix for IE
 if (leftValue == "auto") { leftValue = 0; };

 var movement = parseFloat(leftValue, 10) - panelWidth;

 if (movement == tooFar) {
  $(".slide img").animate({
   "top": -600
  }, 1000, function() {
   $("#mover").animate({
    "left": 0
   }, function() {
    $(".slide img").animate({
     "top": 40
    });
   });
  });
 }
 else {
  $(".slide img").animate({
   "top": -600
  }, 1000, function() {
   $("#mover").animate({
    "left": movement
   }, function() {
    $(".slide img").animate({
     "top": 40
    });
   });
  });
 }
}

$(function(){

    var $slide1 = $("#slide-1");

 var panelWidth = $slide1.css("width");
 var panelPaddingLeft = $slide1.css("paddingLeft");
 var panelPaddingRight = $slide1.css("paddingRight");

 panelWidth = parseFloat(panelWidth, 10);
 panelPaddingLeft = parseFloat(panelPaddingLeft, 10);
 panelPaddingRight = parseFloat(panelPaddingRight, 10);

 panelWidth = panelWidth + panelPaddingLeft + panelPaddingRight;

 var numPanels = $(".slide").length;
 var tooFar = -(panelWidth * numPanels);
 var totalMoverwidth = numPanels * panelWidth;
 $("#mover").css("width", totalMoverwidth);

 $("#slider").append('<a href="#" id="slider-stopper">Stop</a>');

 sliderIntervalID = setInterval(function(){
  doMove(panelWidth, tooFar);
 }, delayLength);

 $("#slider-stopper").click(function(){
  if ($(this).text() == "Stop") {
   clearInterval(sliderIntervalID);
    $(this).text("Start");
  }
  else {
   sliderIntervalID = setInterval(function(){
    doMove(panelWidth, tooFar);
   }, delayLength);
    $(this).text("Stop");
  }

 });

});

Upvotes: 0

Views: 196

Answers (2)

keegan3d
keegan3d

Reputation: 11315

It should work to change the property being animated to "opacity":

$(".slide img").animate({
    "opacity": 1
},

Upvotes: 1

422
422

Reputation: 5770

Im no jquery expert, but could you simply replace, .animate with .fadeIn("slow")

Upvotes: 0

Related Questions