简体   繁体   English

使用Stripe自定义字体src

[英]Custom font src with Stripe

Using this as reference https://stripe.com/docs/elements/reference#stripe-elements 以此为参考https://stripe.com/docs/elements/reference#stripe-elements

I'm trying create a custom font src to pass to my stripe elements: 我正在尝试创建一个自定义字体src传递给我的条带元素:

var elements = stripe.elements(
    {
        font: {
            family:'Effra',
            src: "url('https://cuddlecompanions.org/wp-content/themes/diamondphoenix/fonts/effra.eot')"
        }
    }
);

var style = {
    base: {
        fontFamily: 'Effra'  
    }
}

But the font is not displaying as planned.. 但字体没有按计划显示..

Any help would be appreciated: 任何帮助,将不胜感激:

Thanks guys for the help. 谢谢大家的帮助。 I got a help on stripe's IRC. 我得到了条纹IRC的帮助。 It might've been the missing commas, and also switched to ttf. 它可能是缺少的逗号,也切换到ttf。 At any rate hope this can help someone: 无论如何希望这可以帮助某人:

var elements = stripe.elements({
    fonts: [
        {
            family: 'Effra',

            src: 'local("Effra"), local("effra"), url(https://cuddlecompanions.org/wp-content/themes/diamondphoenix/fonts/effra.ttf) format("truetype")',
            unicodeRange: 'U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215',
        },
    ]
});


<style>
@font-face {
font-family: 'Effra';
font-weight: 400;
src: local("Effra"), local("effra"), url(https://cuddlecompanions.org/wp-content/themes/diamondphoenix/fonts/effra.ttf) format("truetype");
unicodeRange: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215;
} 
</style> 

stripe.elements takes an options object. stripe.elements采用选项对象。

stripe.elements([options])

fonts 字体
An array of custom fonts Elements created from the elements object can use. 自定义字体数组从元素对象创建的元素可以使用。

It seems that it's expecting an array. 似乎它期待一个阵列。

Try changing to 尝试改为

var elements = stripe.elements(
    {
        fonts: [{
            family:'Effra',
            src: "url('https://cuddlecompanions.org/wp-content/themes/diamondphoenix/fonts/effra.eot')"
        }]
    }
);

Here is the my working example (it works on my side). 这是我的工作示例(它适用于我)。

var stripe = Stripe('pk_test_........'); // paste your stripe public key here

var elements = stripe.elements({
  fonts: [
    {
      // integrate your font into stripe
      cssSrc: 'https://fonts.googleapis.com/css?family=Montserrat:400,500',
    }
  ]
});

const style = {
  base: {
    color: '#32325d',
    fontFamily: 'Montserrat, sans-serif',  // set integrated font family
    fontSmoothing: 'antialiased',
    fontSize: '17px',
    '::placeholder': {
      color: '#e5286a'
    }
  }
};

this.card = elements.create('card', {
  style: style,
  hidePostalCode: true,
});
this.card.mount(this.cardInfo.nativeElement);

I think its a formatting error , you are missing some commas. 我认为这是一个格式错误,你缺少一些逗号。

  var elements = stripe.elements({
           fonts: [
                {
                family:'Effra',
                src: "url('https://cuddlecompanions.org/wp-content/themes/diamondphoenix/fonts/effra.eot')",
                },
            ]
        });

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

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