2014-06-18 4 views
0

스크롤 할 때 페이지 하단에 div를 수정하는 jquery 코드가 있습니다.창 너비가 468px 미만인 경우 jquery 함수를 호출하십시오.

var ad = jQuery('.top_leaderboard_container'); 
var min_scroll = 25; // Set your minimum scroll amount here 
jQuery(window).scroll(
    function() { 
     var t = jQuery(window).scrollTop(); 
     if (t > min_scroll) { 
      // define your scroll CSS here 

      ad.css({position: "fixed" , bottom:"0"}); 
     } else { 
      // define your non-scrolled CSS here 

      ad.css({position: "relative"}); 
     } 
    } 
); 

이 기능은 웹 사이트 너비가 468px 미만인 경우에만 발생합니다. 이것을 달성하기 위해 jquery 코드를 추가해야합니까?

답변

0
if ($(window).width() < 468) { 

    // your logic here 

} 

이 트릭

1
// call your code on page load 
jQuery(document).ready(function() { 
    widthSmallerThan(468); 
}); 

// call it every time the window size changes and is smaller than... 
jQuery(window).resize(function() { 
    widthSmallerThan(468); 
}); 

var widthSmallerThan = function(width) { 
    if (jQuery(window).width() < width) { 
     // your code 
    } 
}; 
+0

고마워요! 그것은 @algorhythm – Hussain

+0

내가 더 이상 한 가지 내가 물어보고 싶은 일을 할 때 나는 내가 바닥에 수정하려는 내 div 클래스에 Z- 인덱스를 추가해야합니까? – Hussain

+0

예. div가'ad'이므로 'ad.css ('z-index ', 101); 또는 무엇을 의미합니까? – algorhythm

0

당신은 CSS3에서 사용할 수있는 미디어 쿼리를 사용할 수있다 할 것입니다.

@media (max-width: 468px) { 
    .top_leaderboard_container{position: "relative";} 
} 

@media (min-width: 469px) { 
    .top_leaderboard_container{position: "fixed"; bottom:"0";} 
} 

자세한 내용을 보려면 here을 클릭하십시오.

관련 문제