首页 \ 问答 \ 整洁2.0平板电脑媒体查询不起作用(Neat 2.0 tablet media query not working)

整洁2.0平板电脑媒体查询不起作用(Neat 2.0 tablet media query not working)

在Neat 1.8中,我为媒体查询使用了3个断点,他们的位置如下所示:

$mobile: new-breakpoint(min-width 320px max-width 767px);
$tablet: new-breakpoint(min-width 768px max-width 1024px);
$desktop: new-breakpoint(min-width 1025px);

但在Neat 2.0中,我无法让$tablet媒体查询工作,只有桌面和$mobile工作,但完全绕过$tablet

我的SCSS文件

$neat-grid: (
 columns: 12,
 gutter: 2em,
);

$mobile: (
 columns: 12,
 gutter: 1em,
 media: 'screen and (min-width: 320px) and (max-width: 767px)'
);

$tablet: (
 columns: 12,
 gutter: 1.1em,
 media: 'screen and (min-width 768px max-width 1024px)'
);

.element {
 @include grid-column(3);

 @include grid-media($mobile){
   @include grid-column(4);
 }

 @include grid-media($tablet){
   @include grid-column(6);
 }
}

我的网站很简单,因此我喜欢为我的媒体查询使用一个范围,例如:(最小宽度768px最大宽度1024px。这适用于Neat 1.8,但升级后我无法获得$tablet的工作。

我在想什么?


In Neat 1.8 I used 3 breakpoints for my media queries and they where as follows:

$mobile: new-breakpoint(min-width 320px max-width 767px);
$tablet: new-breakpoint(min-width 768px max-width 1024px);
$desktop: new-breakpoint(min-width 1025px);

But in Neat 2.0 I just can´t get the $tablet media query to work, only desktop and $mobile work, but bypasses $tablet completely.

My SCSS file

$neat-grid: (
 columns: 12,
 gutter: 2em,
);

$mobile: (
 columns: 12,
 gutter: 1em,
 media: 'screen and (min-width: 320px) and (max-width: 767px)'
);

$tablet: (
 columns: 12,
 gutter: 1.1em,
 media: 'screen and (min-width 768px max-width 1024px)'
);

.element {
 @include grid-column(3);

 @include grid-media($mobile){
   @include grid-column(4);
 }

 @include grid-media($tablet){
   @include grid-column(6);
 }
}

My sites are simple and therefore I like to use a range for my media queries e.g: (min-width 768px max-width 1024px. This working perfectly for Neat 1.8 but after upgrading I can't get $tablet to work.

What am I missing??


原文:https://stackoverflow.com/questions/43161123
更新时间:2023-05-04 16:05

最满意答案

在进一步检查后,正在“验证”的项目仍然使用ajax added_to_cart 。 因此,jQuery代码可以在“added_to_cart”委托事件上发送ajax请求时使用相同的逻辑。 在那个请求中,php将获得一个购物车项目被添加到购物篮的尝试次数 ,并将其返回给jQuery。 如果该计数符合条件,则会显示甜言蜜语消息:

感谢@LoicTheAztec帮助提供部分解决方案。

// remove the filter 
add_filter( 'woocommerce_cart_redirect_after_error', '__return_false'); 

add_action( 'woocommerce_add_to_cart_validation', 'restrict_only_one_item_in_cart' );

 function restrict_only_one_item_in_cart($cart_item_data) {

   global $woocommerce;
   $item_count = $woocommerce->cart->cart_contents_count;

   if($item_count >= 20)
   {
      //WE WILL EXECUTE JAVASCRIPT BELOW INSTEAD
      return false;
   }

   return $cart_item_data;
}

// The Jquery script
add_action( 'wp_footer', 'cart_full' );
function cart_full() {
    ?>
    <script src="https://unpkg.com/sweetalert2@7.20.1/dist/sweetalert2.all.js"></script>
    <script type="text/javascript">
    jQuery( function($){
        // The Ajax function
        $(document.body).on('added_to_cart', function() {
            console.log('event');
            $.ajax({
                type: 'POST',
                url: wc_add_to_cart_params.ajax_url,
                data: {
                    'action': 'checking_cart_items',
                    'added' : 'yes'
                },
                success: function (response) {
                    if( response >= 20 ){
                        swal(
                            'Youve added the max items!',
                            'Change Your box',
                            'error'
                        );
                    }
                }
            });
        });
    });
    </script>
    <?php
}

Upon further inspection, items which are being "validated" are still called with the ajax added_to_cart. Therefore the same logic can be used where jQuery code will send an ajax request on "added_to_cart" delegated event. On that request php will get the number of attempts a cart item has been added to the basket and will return it to jQuery. If that count has met a condition, it will display sweet-alert message:

Thanks to @LoicTheAztec for helping provide part of the solution.

// remove the filter 
add_filter( 'woocommerce_cart_redirect_after_error', '__return_false'); 

add_action( 'woocommerce_add_to_cart_validation', 'restrict_only_one_item_in_cart' );

 function restrict_only_one_item_in_cart($cart_item_data) {

   global $woocommerce;
   $item_count = $woocommerce->cart->cart_contents_count;

   if($item_count >= 20)
   {
      //WE WILL EXECUTE JAVASCRIPT BELOW INSTEAD
      return false;
   }

   return $cart_item_data;
}

// The Jquery script
add_action( 'wp_footer', 'cart_full' );
function cart_full() {
    ?>
    <script src="https://unpkg.com/sweetalert2@7.20.1/dist/sweetalert2.all.js"></script>
    <script type="text/javascript">
    jQuery( function($){
        // The Ajax function
        $(document.body).on('added_to_cart', function() {
            console.log('event');
            $.ajax({
                type: 'POST',
                url: wc_add_to_cart_params.ajax_url,
                data: {
                    'action': 'checking_cart_items',
                    'added' : 'yes'
                },
                success: function (response) {
                    if( response >= 20 ){
                        swal(
                            'Youve added the max items!',
                            'Change Your box',
                            'error'
                        );
                    }
                }
            });
        });
    });
    </script>
    <?php
}

相关问答

更多

相关文章

更多

最新问答

更多
  • python的访问器方法有哪些
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。
  • 响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
  • 在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
  • NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
  • 元素上的盒子阴影行为(box-shadow behaviour on elements)
  • Laravel检查是否存在记录(Laravel Checking If a Record Exists)
  • 设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
  • 想学Linux 运维 深圳有哪个培训机构好一点
  • 为什么有时不需要在lambda中捕获一个常量变量?(Why is a const variable sometimes not required to be captured in a lambda?)
  • 在Framework 3.5中使用服务器标签<%=%>设置Visible属性(Set Visible property with server tag <%= %> in Framework 3.5)
  • AdoNetAppender中的log4net连接类型无效(log4net connection type invalid in AdoNetAppender)
  • 错误:发送后无法设置标题。(Error: Can't set headers after they are sent. authentication system)
  • 等待EC2实例重启(Wait for an EC2 instance to reboot)
  • 如何在红宝石中使用正则表达式?(How to do this in regex in ruby?)
  • 使用鼠标在OpenGL GLUT中绘制多边形(Draw a polygon in OpenGL GLUT with mouse)
  • 江民杀毒软件的KSysnon.sys模块是什么东西?
  • 处理器在传递到add_xpath()或add_value()时调用了什么顺序?(What order are processors called when passed into add_xpath() or add_value()?)
  • sp_updatestats是否导致SQL Server 2005中无法访问表?(Does sp_updatestats cause tables to be inaccessible in SQL Server 2005?)
  • 如何创建一个可以与持续运行的服务交互的CLI,类似于MySQL的shell?(How to create a CLI that can interact with a continuously running service, similar to MySQL's shell?)
  • AESGCM解密失败的MAC(AESGCM decryption failing with MAC)
  • SQL查询,其中字段不包含$ x(SQL Query Where Field DOES NOT Contain $x)
  • PerSession与PerCall(PerSession vs. PerCall)
  • C#:有两个构造函数的对象:如何限制哪些属性设置在一起?(C#: Object having two constructors: how to limit which properties are set together?)
  • 平衡一个精灵(Balancing a sprite)
  • n2cms Asp.net在“文件”菜单上给出错误(文件管理器)(n2cms Asp.net give error on Files menu (File Manager))
  • Zurb Foundation 4 - 嵌套网格对齐问题(Zurb Foundation 4 - Nested grid alignment issues)
  • 湖北京山哪里有修平板计算机的