我和woo一起在一个项目上工作。 在网站的移动版本上,购物车是一个弹出窗口。 当客户添加许多不同的产品时,他必须向下滚动才能看到“查看购物车”,“付款”按钮。
我尝试添加自动滚动js代码。有人打开购物车时,它必须自动向下滚动并停在“查看购物车”,“付款”按钮上。
我找到了一些“自动滚动到div”的代码,但没有一个对我有用。
我玩的一个简单的js代码是
$('#start').click(function() {
$('html,body').animate({
scrollTop: $('#bodycontainer').position().top
}, 1000 );});
但是什么也没发生。 有什么帮助吗? 谢谢
答案 0 :(得分:0)
如果是滚动的容器,则您尝试滚动错误的内容。替换为:
Sub getRandomRecords()
Dim lastRow As Integer
Dim shAudit As Worksheet
Dim shData As Worksheet
Dim r As Integer
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
Dim key As Variant
Set shAudit = ThisWorkbook.Sheets("Sheet1")
Set shData = ThisWorkbook.Sheets("Sheet2")
lastRow = shData.Range("A" & shData.Rows.Count).End(xlUp).Row
'Pick 5 random records with no repeats
Do Until dict.Count = 5
r = Application.WorksheetFunction.RandBetween(2, lastRow)
If Not dict.Exists(r) Then
dict.Add r, r
End If
Loop
r = 0
'Copy the randomly selected records to the audit tab
For Each key In dict.Keys
shData.Range("A1:H1").Offset(key - 1, 0).Copy shAudit.Range("A5:H5").Offset(r, 0)
r = r + 1
Next key
End Sub
现在,如果您不使用容器,则不妨添加一个容器。
答案 1 :(得分:0)
我完全困惑
我的迷你购物车代码是
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
global $woocommerce;
?>
<?php do_action( 'woocommerce_before_mini_cart' ); ?>
<div class="cart_list <?php echo esc_attr( $args['list_class'] ); ?>">
<?php if ( ! WC()->cart->is_empty() ) : ?>
<?php
foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key );
if ( $_product && $_product->exists() && $cart_item['quantity'] > 0 && apply_filters( 'woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) ) {
$product_name = apply_filters( 'woocommerce_cart_item_name', $_product->get_name(), $cart_item, $cart_item_key );
$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
$product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
$product_permalink = apply_filters( 'woocommerce_cart_item_permalink', $_product->is_visible() ? $_product->get_permalink( $cart_item ) : '', $cart_item, $cart_item_key );
?>
<div class="media widget-product">
<div class="media-left">
<a href="<?php echo esc_url( $product_permalink ); ?>" class="image pull-left">
<?php echo trim($thumbnail); ?>
</a>
</div>
<div class="cart-main-content media-body">
<h3 class="name">
<a href="<?php echo esc_url( $product_permalink ); ?>">
<?php echo trim($product_name); ?>
</a>
</h3>
<p class="cart-item">
<?php echo wc_get_formatted_cart_item_data( $cart_item ); ?>
<?php echo apply_filters( 'woocommerce_widget_cart_item_quantity', '<span class="quantity">' . sprintf( '%s × %s', $cart_item['quantity'], $product_price ) . '</span>', $cart_item, $cart_item_key ); ?>
</p>
<?php
echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
'<a href="%s" class="remove remove_from_cart_button" aria-label="%s" data-product_id="%s" data-cart_item_key="%s" data-product_sku="%s">×</a>',
esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
__( 'Remove this item', 'opal_drop' ),
esc_attr( $product_id ),
esc_attr( $cart_item_key ),
esc_attr( $_product->get_sku() )
), $cart_item_key );
?>
</div>
</div>
<?php
}
}
?>
<?php else : ?>
<div class="empty"><?php esc_html_e( 'No products in the cart.', 'opal_drop' ); ?></div>
<?php endif; ?>
</div><!-- end product list -->
<?php if ( ! WC()->cart->is_empty() ) : ?>
<p class="total"><strong><?php esc_html_e( 'Subtotal', 'opal_drop' ); ?>:</strong> <?php echo WC()->cart->get_cart_subtotal(); ?></p>
<?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
<p class="buttons clearfix">
<a href="<?php echo esc_url(wc_get_cart_url()); ?>" class="btn view-cart btn-default pull-left wc-forward"><?php esc_html_e( 'View Cart', 'opal_drop' ); ?></a>
<a href="<?php echo esc_url( wc_get_checkout_url() ); ?>" class="btn check-out btn-primary text-white pull-right checkout wc-forward"><?php esc_html_e( 'Checkout', 'opal_drop' ); ?></a>
</p>
<?php endif; ?>
<?php do_action( 'woocommerce_after_mini_cart' ); ?>
我尝试这个
jQuery(document).ready(function($){
if ( $(window).width() < 768 || window.Touch) {
$('html, body').animate({
scrollTop: $("#cart-main-content .media-body").offset().top
}, 2000);
}
});
没有运气。现在我用jQuery练习