2012-06-18 4 views
0

나는이 스크립트를 조정하려고하는데 이미지를 클릭하면 다른 div가 표시되고 다른 정보를 클릭하면 해당 정보가 표시되고 둘 다 표시되지 않습니다.관련 Jquery 표시/숨기기

(function ($) { 
    $.fn.showHide = function (options) { 
     //default vars for the plugin 
     var defaults = { 
      speed: 1000, 
      easing: '', 
      changeText: 0, 
      showText: 'Show', 
      hideText: 'Hide' 
     }; 
     var options = $.extend(defaults, options); 
     $(this).click(function() { 
      $('.toggleDiv').slideUp(options.speed, options.easing); 
      // this var stores which button you've clicked 
      var toggleClick = $(this); 
      // this reads the rel attribute of the button to determine which div id to toggle 
      var toggleDiv = $(this).attr('rel'); 
      // here we toggle show/hide the correct div at the right speed and using which easing effect 
      $(toggleDiv).slideToggle(options.speed, options.easing, function() { 
       // this only fires once the animation is completed 
       if (options.changeText == 1) { 
        $(toggleDiv).is(":visible") ? toggleClick.text(options.hideText) : toggleClick.text(options.showText); 
       } 
      }); 
      return false; 
     }); 
    }; 
})(jQuery); 

알려 주시기 바랍니다. 감사합니다 http://papermashup.com/simple-jquery-showhide-div/

+2

어떤 문제가 발생합니까? 너 뭐 해봤 니? –

+0

얻는 방법에 문제가있어서 다른 div를 계속 확장하지 않습니다. 나는 그저 그것을하는 법을 알고 싶었습니다. 나는 JQUERY와 OOP에 대해 처음 보았습니다. –

답변

0

jQuery toggle event handler을 보면 두 가지 기능을 요소에 바인딩하고 다른 클릭으로 실행시킬 수 있습니다. 당신은 당신이 볼 수있어 여부에있어 클릭하는 추적하지 않아도 그 방법 등

간단히, 당신은 다음 두 가지 기능을 가질 것 toggle 핸들러로 click 핸들러를 대체 할 것 :

$(this).toggle(function() { 
     //what to do when your element is in its initial state 
    }, function() { 
     //what to do when your element is in its "clicked once" state 
    } 
+0

힌트를 제공해 주셔서 감사합니다. 나는 게으르지 않고 있지만 당신은 무엇을 제안 할 것입니다. 나는 Jquery에 정말로 좋고, 단지 그것 주위에 나의 머리를 얻을 수 없다. –

+0

나는 당신이하려는 일에 대해 (나에게) 분명하지 않기 때문에 나는 정말로 추천 할 수 없다. 마치 당신의 함수가 필요 이상으로 복잡하고'click '대신에'toggle'을 사용하는 것이 더 쉬울 것처럼 보입니다. –

+0

아, 제이콥을 봅니다. 그것은 훨씬 더 의미가 있습니다. 나는 그것을 대신 사용할 것이다. 참으로 대단히 감사합니다. –