2012-05-28 5 views
1
$(function() { 
    $(".flexslider img") 
     .mouseover(function() { 
      var src = $(this).attr("src").match(/[^\.]+/) + "-bw.png"; 
      $(this).attr("src", src); 
     }) 
     .mouseout(function() { 
      var src = $(this).attr("src").replace("-bw.png", ".png"); 
      $(this).attr("src", src); 
     }); 
    }); 

나는 이전 SRC + -bw 또는 접미사 마우스 오버를 어느 때 워드 프레스 테마의 대부분의 페이지에 나타나는 회전 목마, 나는 새로운 ATTR에있는 회전 목마에 모든 이미지를 변경할 필요가있다 . 그러나 트위닝하거나 애니메이션을 적용해야합니다. 위의 코드는 이미지를 변경하지만 움직이지 않습니다. 또한 많은 사람들은 호버에 드러날 이미지를 미리로드 할 것을 제안합니까?애니메이션 이미지 속성 변경

답변

4

애니메이션의 어떤 종류의 당신이 필요로 할 ? 페이딩?

$(function() { 
    $(".flexslider img") 
     .mouseover(function() { 
      var src = $(this).attr("src").match(/[^\.]+/) + "-bw.png"; 
      $(this).fadeOut("fast").attr("src", src).fadeIn("fast"); 
     }) 
     .mouseout(function() { 
      var src = $(this).attr("src").replace("-bw.png", ".png");     
      $(this).fadeOut("fast").attr("src", src).fadeIn("fast"); 
     }); 
    }); 
+0

감사 BRAM이 완벽하다! – gilesadamthomas

+0

@gilesadamthomas 여러분, 천만입니다. –

+1

위의 코드는 먼저 속성을 바꾼 다음 페이드 아웃 한 다음에 있습니다. | ** 여기는 더 좋은 것입니다. ** fadeOut (140, function() {\t \t \t \t \t \t \t $ (this) .attr ('src', 'http : // tinyurl. fadeIn (140); * fadoOut() *은 매개 변수에서 두 번째 함수를 취합니다. [예] (http://jsfiddle.net/98y88mxj/) – animaacija

0

당신은 그것을 설명, 여기에 크로스 페이드를 할 필요가있을 것이다 :

http://jqueryfordesigners.com/image-cross-fade-transition/

당신이 뭔가를 할 수 있습니다 :

crossFade = function(element, to_src) { 
    element = $(element); //maybe this isn't even needed. 
    element.style = "display: block; position: absolute; top:0; left:0;"; //please replace this with four .css() calls ;) and double check the positioning 
    parentElement = $(element.parentNode); 
    newElement = $("<img/>", { 
     src: to_src, 
     style: "display: none; position: absolute; top:0; left:0;" 
    } 
    newElement.appendTo(parentElement); 
    //please check in your dom if both images are in the carrousels-list-node, as I might have errored ;) 
    newElement.fadeIn(5000, (function(el) { return function() { el.remove(); }; })(element)); 
};