简体   繁体   English

在Shopify或网站上安装JS代码

[英]Installing JS code on Shopify or Website

thanks in advance. 提前致谢。

I've created this JS function which is working on test websites but it not working on shopify. 我创建了此JS函数,该函数可在测试网站上使用,但不适用于shopify。

How can i call it into a product page? 如何将其称为产品页面? Probably there is some mistake in there 可能那里有一些错误

Thank you 谢谢

 var output, started, duration, desired; // Constants duration = 5000; desired = '50'; // Initial setup output = $('#output'); started = new Date().getTime(); // Animate! animationTimer = setInterval(function() { // If the value is what we want, stop animating // or if the duration has been exceeded, stop animating if (output.text().trim() === desired || new Date().getTime() - started > duration) { console.log('animating'); // Generate a random string to use for the next animation step output.text('' + Math.floor(Math.random() *(50 - 25) + 25) ); } else { console.log('animating'); // Generate a random string to use for the next animation step output.text('' + Math.floor(Math.random() * (50 - 25) + 25) ); } }, 4000); 
 #output { margin: 20px; padding: 20px; background: gray; border-radius: 10px; font-size: 80px; width: 80px; color: white; } 
 <div id="output"></div> 

Since I ran out of room in the comments if you click the arrows in the top right of your product page and copy and paste this code in and it'll work just fine. 由于我单击了产品页面右上角的箭头,然后将其复制并粘贴到注释中,因此注释中的空间不足,因此可以正常工作。

If it is still not working the only other thing I can think of is maybe you don't have jquery included in your theme since your code uses jquery. 如果仍然无法正常工作,我唯一想到的另一件事可能是您的主题中没有包含jquery,因为您的代码使用了jquery。 To validate that your theme already has jquery go to theme.liquid ctrl + f 'jquery' 为了验证你的主题已经拥有jQuery的去theme.liquid 按Ctrl + F“的jQuery”

If you find it, I am uncertain what problem you are having; 如果找到它,我不确定您遇到什么问题; if not add it to your theme and you test it again. 如果没有将其添加到您的主题中,然后再次进行测试。

<div id="output"></div>
<script>// <![CDATA[
var output, started, duration, desired;

// Constants
duration = 5000;
desired = '50';

// Initial setup
output = $('#output');
started = new Date().getTime();

// Animate!
animationTimer = setInterval(function() {
    // If the value is what we want, stop animating
    // or if the duration has been exceeded, stop animating
    if (output.text().trim() === desired || new Date().getTime() - started > duration) {
        console.log('animating');
        // Generate a random string to use for the next animation step
        output.text('' + Math.floor(Math.random() *(50 - 25) + 25) 

        );

    } else {
        console.log('animating');
        // Generate a random string to use for the next animation step
        output.text('' + Math.floor(Math.random() * (50 - 25) + 25)

        );
    }
}, 4000);
// ]]></script>

Ok solved it 好解决了

I should install Jquery like this 我应该这样安装Jquery

{{ '//ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js' | {{'//ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js'| script_tag }} script_tag}}

and not like this 而不是这样

etc.etc.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM