【问题标题】:CSS class not getting added using javascript on mobile version of website没有在移动版网站上使用 javascript 添加 CSS 类
【发布时间】:2021-01-06 21:16:01
【问题描述】:

我已使用以下代码将类添加到 Wordpress 网站上的 svg 图像。

window.addEventListener('load', function () {
    const svg = document.querySelector('svg')

    if (svg) {
        const items = document.querySelectorAll(
            '.woocommerce-grouped-product-list-item'
        )

        if (items) {
            items.forEach((item) => {
                item.addEventListener('mouseenter', (e) => {
                    item.classList.add('tab-brackground--active')
                    const text = e.target.children[0].innerText
                    jQuery(`[data-section="${text.toLowerCase()}"]`).addClass(
                        'svg--active'
                    )
                })
            })
        }
    }
}) 



item.classList.add('tab-brackground--active')

适用于我的移动版和桌面版,而

jQuery(`[data-section="${text.toLowerCase()}"]`).addClass('svg--active')

仅适用于我的桌面版本。

您可以通过此链接自行查看 - https://ticketblaster.com.au/product/keith-urban-melbourne-friday-10th-december-2021/

我能做些什么来解决这个问题?

【问题讨论】:

    标签: javascript html jquery css wordpress


    【解决方案1】:

    @Ziyak,您使用 mouseenter 作为 eventListener,它仅适用于台式机,不适用于移动设备。尝试在移动设备上使用 touchmove、touchstart 和 touchend 等事件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-19
      • 2011-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多