整洁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
最满意答案
在进一步检查后,正在“验证”的项目仍然使用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 }
相关问答
更多-
通过本地客户端程序获取服务器mysql数据库信息[2023-04-27]
ajax -
你的href是"/cart/?add-to-cart=post->ID; ?>"这是基本上你重定向到购物车页面并将产品添加到购物车。 试试这个像href="?add-to-cart=post->ID; ?>" ,它应该让你在同一页面上。 Your href is "/cart/?add-to-cart=post->ID; ?>" which basicaly sais that you redirec ...
-
使用AJAX添加变体到购物车 - WooCommerce API?(Add a Variation to Cart using AJAX - WooCommerce API?)[2024-04-16]
您可以调查WooCommerce如何通过ajax直接在代码中将项目添加到购物车....回调位于includes/class-wc-ajax.php 。 WooCommerce已经在产品“循环”(产品档案)上做到了这一点,所以我不认为你需要重新发明轮子,如果他们现有的代码不适合你想要做的事情,那么你应该可以借用很重要。 该文件的开头与所有的WooCommerce Ajax动作都有一个循环,但我们可以追踪到添加到购物车基本上是这样的: add_action( 'wp_ajax_nopriv_woocommerc ... -
当我单击按钮时,它会将产品添加到购物车,但甜蜜警报不会激活,直到第3次点击,但然后工作。但仅适用于列表中的第一个产品。 这是因为第一个按钮单击发送您的ajax请求,然后当它返回时,您将甜蜜警报绑定为单击处理程序到“document.querySelector('。add-to-cart-success')”的单击事件。 换句话说,第一次点击是绑定事件,后续点击,绑定后,将触发甜蜜警报。 只需单击第一个产品上的添加到报价几次。 第二个产品应该给出错误但不会。 第三个应该添加产品。 所有三个按钮都有“add-t ...
-
你忘记了这个重要的过程: add_action('wp_enqueue_scripts', 'add_my_ajax_scripts'); add_my_ajax_scripts(){ // Here you register your script located in a subfolder `js` of your active theme wp_enqueue_script( 'ajax-script', get_template_directory_uri().'/js/scri ...
-
以下是此问题的解决方案,运行$woocommerce->cart->maybe_set_cart_cookies(); 添加任何项目后,所以相同的功能如下所示: function es_add_to_cart() { global $woocommerce; $product_id = $_GET['product_id']; $woocommerce->cart->add_to_cart( $product_id ); $woocommerce->cart ...
-
基于这个现有的答案,这里是在Woocommerce存档页面中使这项工作正确的方法,其中在添加到购物车按钮上启用了Ajax。 在ajax上添加按钮将被隐藏: add_action( 'storefront_header', 'shop_button_when_empty_cart', 40 ); function shop_button_when_empty_cart() { $style = WC()->cart->get_cart_contents_count() > 0 ? ' style=" ...
-
在Ajax Woocommerce上显示甜蜜提醒添加到购物车验证(Display a sweet alert on Ajax Woocommerce Add To Cart Validation)[2023-11-26]
在进一步检查后,正在“验证”的项目仍然使用ajax added_to_cart 。 因此,jQuery代码可以在“added_to_cart”委托事件上发送ajax请求时使用相同的逻辑。 在那个请求中,php将获得一个购物车项目被添加到购物篮的尝试次数 ,并将其返回给jQuery。 如果该计数符合条件,则会显示甜言蜜语消息: 感谢@LoicTheAztec帮助提供部分解决方案。 // remove the filter add_filter( 'woocommerce_cart_redirect_afte ... -
添加变量产品(AJAX)后更新WooCommerce购物车(Updating WooCommerce cart after adding a variable product (AJAX))[2023-05-04]
更新,如果我将以下内容添加到我的functions.php中似乎有效 add_action( 'wp_ajax_nopriv_woocommerce_add_variation_to_cart', 'so_27270880_add_variation_to_cart' ); add_action( 'wp_ajax_woocommerce_add_variation_to_cart', 'so_27270880_add_variation_to_cart' ); 这意味着,一个用于登录管理员,一个用于普通 ... -
正如我在评论中提到的,你几乎可以借用核心WooCommerce功能。 首先,这是我们将尝试ajaxify的按钮: bla bla 其次,我们将加载我们的自定义脚本并传递重要的变量,例如admin ajax和checkout urls。 add_action( 'wp_enqueue_scripts', 'so_load_script', 20 ); f ...