열림 닫힘 버튼 이미지 다르게..

열림 닫힘 버튼 이미지 다르게..

QA

열림 닫힘 버튼 이미지 다르게..

본문

우측에 닫혔다 열렸다 하는 슬라이딩 되는 메뉴?패널? 소스를 적용했는데요.

이소스는 패널이 닫혀도 열려도 클릭버튼이 하나의 이미지인데 열렸있을때와 닫혀있을때 버튼의 이미지를 다르게 하고싶은데 아는게 없다보니 다른 소스에서 따다가 적용도 해봤는데 잘되나 싶더니 쿠키때문인지 이상해지더라구요...

 

아래는 다른소스에서 가져온 열림 닫힘 이미지가 다르게 되어있는 스크립트이구요.

 

$(function(){

 var vi = "on";
$(".box ..handle").click(function(){
       if(vi == "off"){
           $(".box").animate({"right":"0px"});
           $(".handle").html("<img src='img1.jpg'>");
           vi = "on";
       }else{
           $(".box").animate({"right":"-102px"});  // 메뉴 넓이 만큼 - 해준다.
           $(".handle").html("<img src='img2.jpg'>");
           vi = "off";
      }
 });

});

 

------------------------------------------------------

이 아래는 적용해놓은 슬라이딩메뉴입니다.

이 슬라이딩 메뉴에 위처럼 버튼이미지 열림 닫힘시 달라지도록 적용하려면 소스 수정을 어찌해야하는지요? ㅜ ㅜ

 

(function($){
    $.fn.tabSlideOut = function(callerSettings) {
        var settings = $.extend({
            tabHandle: '.handle',
            speed: 300,
            action: 'click',
            tabLocation: 'left',
            topPos: '200px',
            leftPos: '20px',
            fixedPosition: false,
            positioning: 'absolute',
            pathToTabImage: null,
            imageHeight: null,
            imageWidth: null,
            onLoadSlideOut: true                  
        }, callerSettings||{});
        settings.tabHandle = $(settings.tabHandle);

  
  if($.cookie('tabSlide') == 1 || $.cookie('tabSlide') == undefined)
   settings.onLoadSlideOut = true;
  else settings.onLoadSlideOut = false;
  

        var obj = this;
        if (settings.fixedPosition === true) {
            settings.positioning = 'fixed';
        } else {
            settings.positioning = 'absolute';
        }
       
        //ie6 doesn't do well with the fixed option
        if (document.all && !window.opera && !window.XMLHttpRequest) {
            settings.positioning = 'absolute';
        }
       

       
        //set initial tabHandle css
       
        if (settings.pathToTabImage != null) {
            settings.tabHandle.css({
            'background' : 'url('+settings.pathToTabImage+') no-repeat',
            'width' : settings.imageWidth,
            'height': settings.imageHeight
            });
        }
       
        settings.tabHandle.css({
            'display': 'block',
            'textIndent' : '-99999px',
            'outline' : 'none',
            'position' : 'absolute'
        });
       
        obj.css({
            'line-height' : '1',
            'position' : settings.positioning
        });

       
        var properties = {
                    containerWidth: parseInt(obj.outerWidth(), 10) + 'px',
                    containerHeight: parseInt(obj.outerHeight(), 10) + 'px',
                    tabWidth: parseInt(settings.tabHandle.outerWidth(), 10) + 'px',
                    tabHeight: parseInt(settings.tabHandle.outerHeight(), 10) + 'px'
                };

        //set calculated css
        if(settings.tabLocation === 'top' || settings.tabLocation === 'bottom') {
            obj.css({'left' : settings.leftPos});
            settings.tabHandle.css({'right' : 0});
        }
       
        if(settings.tabLocation === 'top') {
            obj.css({'top' : '-' + properties.containerHeight});
            settings.tabHandle.css({'bottom' : '-' + properties.tabHeight});
        }

        if(settings.tabLocation === 'bottom') {
            obj.css({'bottom' : '-' + properties.containerHeight, 'position' : 'fixed'});
            settings.tabHandle.css({'top' : '-' + properties.tabHeight});
           
        }
       
        if(settings.tabLocation === 'left' || settings.tabLocation === 'right') {
            obj.css({
                'height' : properties.containerHeight,
                'top' : settings.topPos
            });
           
            settings.tabHandle.css({'top' : 0});
        }
       
        if(settings.tabLocation === 'left') {
            obj.css({ 'left': '-' + properties.containerWidth});
            settings.tabHandle.css({'right' : '-' + properties.tabWidth});
        }

        if(settings.tabLocation === 'right') {
            obj.css({ 'right': '-' + properties.containerWidth});
            settings.tabHandle.css({'left' : '-' + properties.tabWidth});
        }

        //functions for animation events
       
        settings.tabHandle.click(function(event){
            event.preventDefault();
        });
       
        var slideIn = function() {
           
            if (settings.tabLocation === 'top') {
                obj.animate({top:'-' + properties.containerHeight},
    settings.speed).removeClass('open');
            } else if (settings.tabLocation === 'left') {
                obj.animate({left: '-' + properties.containerWidth},
    settings.speed).removeClass('open');
            } else if (settings.tabLocation === 'right') {
                obj.animate({right: '-' + properties.containerWidth},
    settings.speed).removeClass('open');
            } else if (settings.tabLocation === 'bottom') {
                obj.animate({bottom: '-' + properties.containerHeight},
    settings.speed).removeClass('open');
            }   
           
        };
       
        var slideOut = function() {
           
            if (settings.tabLocation == 'top') {
                obj.animate({top:'-3px'},  settings.speed).addClass('open');
            } else if (settings.tabLocation == 'left') {
                obj.animate({left:'-3px'},  settings.speed).addClass('open');
            } else if (settings.tabLocation == 'right') {
                obj.animate({right:'-3px'},  settings.speed).addClass('open');
            } else if (settings.tabLocation == 'bottom') {
                obj.animate({bottom:'-3px'},  settings.speed).addClass('open');
            }
        };
       
        var clickAction = function(){
            settings.tabHandle.click(function(event){
                if (obj.hasClass('open')) {
                    slideIn();$.cookie('tabSlide', '0', { path: '/' });
                } else {
                    slideOut();$.cookie('tabSlide', '1', {path: '/' });
                }
            });
           
            //clickScreenToClose();
        };
       
        var hoverAction = function(){
            obj.hover(
                function(){
                    slideOut();
                },
               
                function(){
                    slideIn();
                });
               
                settings.tabHandle.click(function(event){
                    if (obj.hasClass('open')) {
                        slideIn();
                    }
                });
                //clickScreenToClose();
               
        };
       
        var slideOutOnLoad = function(){
            slideIn();
            setTimeout(slideOut, 500);
        };
       
        //choose which type of action to bind
        if (settings.action === 'click') {
            clickAction();
        }
       
        if (settings.action === 'hover') {
            hoverAction();
        }
       
        if (settings.onLoadSlideOut) {
            slideOutOnLoad();
        };
       
    };
})(jQuery);

 

이 질문에 댓글 쓰기 :

답변 2

요로코롬 해 보세요~~

 


$(".box .handle").click(function(){
       if(vi == "off"){
           $(".box").animate({"right":"0px"});
           $(".handle").attr("src", "img1.jpg");
           vi = "on";
       }else{
           $(".box").animate({"right":"-102px"});  // 메뉴 넓이 만큼 - 해준다.
           $(".handle").attr("src", "img2.jpg");
           vi = "off";
      }
 });
 
 
 <img src='img1.jpg' id='handle'>

 

 

그런데요...

아래

$(".box ..handle").click(function(){

여기에서

..handle 이거 쩜이 2개 들어갔는데 맞는건가요?

..handle 이게 아니라 .handle 이게 아닐런지요?

답변감사합니다 (__
말씀하신대로 점이 한개들어가는게 맞아요^^; 요기 적으면서 클래스명 복붙하다가 그리되었네요..
근데 알려주신대로 해봤는데 아무런 변화가 없어요..ㅠㅠ 알려주셔도 못하니... 참

handle 부분(클릭버튼부분)이 원래 소스는 이렇게 되어있는데

<a class="handle" href="http://link-for-non-js-users">Content</a>

이부분을 <img src='img1.jpg' id='handle'> 이렇게 바꾸는게 맞나요?

이미지나 레이어에

. 쩜을 찍으면 class

# 샵을 찍으면 id

입니다.

 

그런데 지금 다시보니

제가 .handle 이라고 써 놓고 이미지에는 id="handle" 이라고 써 놨네요. 실수

 

 

.handle 이라고 하면 <img src='img1.jpg' class='handle'>

#handle 이라고 하면 <img src='img1.jpg' id='handle'>

이게 맞습니다.

 

class는 같은 속성이 여러개일때 쓰면 편하고

유일한 것이면 id="handle" 이라고 하는게 좋습니다.

 

 

저도 실수로 답변을 잘못 달았지만 되도록 .handle 말고 #handle로 바꾸시길 권장합니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 0
QA 내용 검색
  • 개별 목록 구성 제목 답변작성자조회작성일
  • 질문이 없습니다.

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT