스크립트 질문이 있습니다..
본문
$( window ).resize(function() {
var width = parseInt($(this).width());
if(width<431){
}else if(width>=431){
move();
}
}).resize();
에서 처음 페이지가 로딩될때는 잘되는데 한번 창의 크기를 조절하고 나면 move()가 if문에서도 move() 스크립트가 실행이 됩니다.
if 문을 분리시켜보기도하고 else 문으로도 빼보기도 해봤는데도 동일하네요..
아래는 move() 스크립트 내용입니다.
function move(){
//scroll header
$(document).scroll(function(){
var con = $(".top_pac");
var img = $("#logo_img");
var pc_menu = $(".pc_menu");
var position = $(window).scrollTop();
if(position > 100){
con.stop().animate({top:'-40px'},70);
pc_menu.stop().animate({top:'60px'},70);
img.stop().animate({width:'130px'},70);
$(".logo").stop().animate({top:'48px'},70);
}else if(position < 100){
con.stop().animate({top:'0px'},70);
pc_menu.stop().animate({top:'40px'},70);
img.stop().animate({width:'230px'},70);
$(".logo").stop().animate({top:'12px'},70);
}
});
};
*시도 해본것.
<script>
$( window ).resize(function() {
var width = parseInt($(this).width());
console.log(width);
if(width<431){
move("stop");
}
if(width>=431){
move("start");
}
}).resize();
function move(str){
if(str =="start"){
//scroll header
...(중략)
}else if(str != "start"){
throw "stop";
}
};
function move2(){
false;
};
</script>
답변 1
scroll 이벤트가 계속 발생하니 다 날리고 아래 코드만 살려 두면 될 듯 한데요.
$(document).scroll(function(){
var width = parseInt($( window ).width());
if(width < 431){
return;
}
var con = $(".top_pac");
var img = $("#logo_img");
var pc_menu = $(".pc_menu");
var position = $(window).scrollTop();
if(position > 100){
con.stop().animate({top:'-40px'},70);
pc_menu.stop().animate({top:'60px'},70);
img.stop().animate({width:'130px'},70);
$(".logo").stop().animate({top:'48px'},70);
}else if(position < 100){
con.stop().animate({top:'0px'},70);
pc_menu.stop().animate({top:'40px'},70);
img.stop().animate({width:'230px'},70);
$(".logo").stop().animate({top:'12px'},70);
}
});
답변을 작성하시기 전에 로그인 해주세요.