Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在低于468px的窗口宽度上调用jquery函数_Jquery - Fatal编程技术网

在低于468px的窗口宽度上调用jquery函数

在低于468px的窗口宽度上调用jquery函数,jquery,Jquery,我有一个jquery代码来修复滚动时页面底部的div 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) {

我有一个jquery代码来修复滚动时页面底部的div

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代码?

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

    // your logic here

}
//你的逻辑在这里 }
这将实现技巧

//在页面加载时调用代码
// 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
    }
};
jQuery(文档).ready(函数(){ 小尔坦(468); }); //每次窗口大小更改且小于时调用它。。。 jQuery(窗口).调整大小(函数(){ 小尔坦(468); }); var widthSmallerThan=函数(宽度){ if(jQuery(window).width()
您可以使用CSS3中提供的媒体查询

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

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

更多信息点击。

我想问的另一件事是,如果我必须在我的div类上添加z-index,我应该怎么做,我想在底部修复它?