jq随机加载背景图

刷新页面随机加载图片

 <style>
        body{
     
                       padding:0;
                       background-attachment: fixed;
                       background-clip: border-box;
                       background-color: #666666;
                       background-origin: padding-box;
                       background-position: center top;
                       background-repeat: no-repeat;
                       background-size: cover;
                       width: 100%;
                       background-image:url("");}
       </style>
</head>
<body>
    
    <script src="./css/jquery-3.5.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
     
            var random_bg=Math.floor(Math.random()*3+1); //三张图轮换
            var bg='url(./images/new_feed/bg_'+random_bg+'.jpg)';
            $("body").css("background-image",bg);
   });
   </script>

图片放在images文件夹下new_feed文件夹中,命名以bg_(x),格式

你可能感兴趣的:(常用的js方法,js,jquery,html,html5)