【问题标题】:Random NoThumb For Blogger博主的随机 NoThumb
【发布时间】:2021-09-16 11:28:33
【问题描述】:

有什么方法可以在博客中制作多个默认缩略图?我想在没有发布图片时随机选择三张图片。

谢谢!

【问题讨论】:

    标签: thumbnails blogger


    【解决方案1】:

    您可以将Math.random() 与数组一起使用,例如

    let thumbnails = ["thumb-1.png","thumb-2.png","thumb-3.png"];
    
    // inside loop or whatever
    if(/*check if post has thumbnail*/){
        // use post thumbnail
        // ...
    } else { // else if no thumbnail use fallback
        let noThumb = thumbnails[Math.floor(Math.random()*thumbnails.length)]
        console.log(noThumb) // random thumbnail
    }
    

    【讨论】:

      猜你喜欢
      • 2014-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多