You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

将Carousel文件滑块转换为普通两列菜单的技术问题咨询

Got it, let's turn that file carousel into a clean, functional two-column menu! I'll walk you through adjusting your HTML, CSS, and JavaScript to match your desired outcome.

First, swap out your existing carousel markup for a simple container that we'll style into two columns. Here's the updated structure:

<!-- Replace your carousel div with this -->
<div id="fileMenu" class="two-column-file-menu">
  <!-- Dynamic file items will populate here -->
</div>

Step 2: Add CSS for Two-Column Layout

Add this CSS to style the container into a responsive two-column grid with clean, interactive items:

.two-column-file-menu {
  display: grid;
  grid-template-columns: repeat(2, 1fr); /* Creates 2 equal-width columns */
  gap: 1.5rem; /* Space between menu items */
  padding: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.file-menu-item {
  padding: 1.2rem;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background-color: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}

.file-menu-item:hover {
  background-color: #f8f9fa;
  border-color: #adb5bd;
}

.file-menu-item a {
  text-decoration: none;
  color: #212529;
  display: block;
}

.file-menu-item small {
  color: #6c757d;
  margin-top: 0.5rem;
  display: inline-block;
}

Step 3: Modify Your JavaScript to Generate Menu Items

Update your getOneDriveFiles function to generate menu items instead of carousel slides. I've also added error handling and extra file details (like size) for better usability:

function getOneDriveFiles(){
  // PnP setup
  $pnp.setup({ baseUrl: "BASE URL" });
  
  // Fetch files from OneDrive folder
  $pnp.sp.web.getFolderByServerRelativeUrl("FOLDER TO GRAB FILES")
    .files.orderBy("Name")
    .get()
    .then(function(files){
      console.log('Fetched files:', files);
      let menuHtml = '';
      
      // Loop through files to build menu items
      $.each(files, function(index, file){
        // Calculate file size in KB for readability
        const fileSizeKB = (file.Length / 1024).toFixed(2);
        
        menuHtml += `
          <div class="file-menu-item">
            <a href="${file.ServerRelativeUrl}" target="_blank">
              <strong>${file.Name}</strong>
            </a>
            <small>Size: ${fileSizeKB} KB | Modified: ${new Date(file.TimeLastModified).toLocaleDateString()}</small>
          </div>
        `;
      });
      
      // Inject the generated menu into the container
      $('#fileMenu').html(menuHtml);
    })
    .catch(function(error){
      console.error('Error loading files:', error);
      // Show error message to users
      $('#fileMenu').html('<p class="text-danger">Oops, failed to load files. Please try again later.</p>');
    });
}

Key Changes Explained

  • Layout: Uses CSS Grid for a responsive two-column setup that adapts to smaller screens (you can add a media query to switch to 1 column on mobile if needed)
  • Interactivity: Hover effects make menu items feel clickable and responsive
  • Usability: Added file size and last modified date to give users more context
  • Error Handling: Catches and displays errors instead of failing silently

Call your getOneDriveFiles() function as you normally would, and you'll have a clean two-column file menu instead of a carousel!

内容的提问来源于stack exchange,提问作者user9727963

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:46:31