创建使用显示/隐藏图层和 Z 索引更改页面内容的下拉菜单

发布于 2024-07-08 07:21:08 字数 317 浏览 9 评论 0原文

我正在尝试为网站创建一个侧边栏,允许用户从下拉菜单中选择一个项目并显示 RSS 源。 提要将根据从列表中选择的项目而变化。 我不知道如何完成这个,但我的第一个想法是使用 z-index 和显示/隐藏图层。 我设置了一层和菜单,但它不允许我更改选择不同菜单项时显示的提要。 有谁知道我怎样才能做到这一点?

我可以实时预览到目前为止我已完成的工作。 它位于网站 CHUD 上,

I am trying to create a sidebar for a site that will allow a user to select an item from a drop down menu and show an RSS Feed. The feed will change depending on which item is selected from the list. I am not sure how to acomplish this, but my first thought was to use z-index and show/hide layers. I have one layer and the menu set up, but it will not allow me to change the feed displayed when a different menu item is selected. Does anyone know how I can acomplish this?

I have a live preview up of what I have gotten done so far. It's located on the site, CHUD,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青春如此纠结 2024-07-15 07:21:08

它使用 jQuery 和 jFeed 插件根据下拉选择替换 DIV 的内容。

// load first feed on document load
$(document).ready(
    function() {
       load_feed( $('select#feedSelect')[0], 'feedDiv' ) ); // pick first
    }
);

function load_feed( ctl, contentArea )  // load based on select
{
   var content = $('#' + contentArea )[0]; //pick first

   content.html( 'Loading feed, please wait...' );

   var feedUrl = ctl.options[ctl.selectedIndex].value;

   $.getFeed( { url: feedUrl,
        function(feed) {
           content.html( '' );
           content.append( '<h1>' + feed.title + '</h1>' );
           feed.items.each( 
              function(i,item) {
                  content.append( '<h2><a href="'
                                     + item.link
                                     + '">' 
                                     + feed.title
                                     + '</a></h2>' );
                  content.append( '<p>' + feed.description + '</p>' );
              }
           );
         }
     });
 }

超文本标记语言

<div>
   <select id=feedSelect onchange="load_feed(this,'feedDiv');" >
      <option value='url-to-first-feed' text='First Feed' selected=true />
      <option value='url-to-second-feed' text='Second Feed' />
      ...
   </select>
   <div id='feedDiv'>
   </div>
</div>

This uses jQuery and jFeed plugin to replace the contents of a DIV based on a dropdown selection.

// load first feed on document load
$(document).ready(
    function() {
       load_feed( $('select#feedSelect')[0], 'feedDiv' ) ); // pick first
    }
);

function load_feed( ctl, contentArea )  // load based on select
{
   var content = $('#' + contentArea )[0]; //pick first

   content.html( 'Loading feed, please wait...' );

   var feedUrl = ctl.options[ctl.selectedIndex].value;

   $.getFeed( { url: feedUrl,
        function(feed) {
           content.html( '' );
           content.append( '<h1>' + feed.title + '</h1>' );
           feed.items.each( 
              function(i,item) {
                  content.append( '<h2><a href="'
                                     + item.link
                                     + '">' 
                                     + feed.title
                                     + '</a></h2>' );
                  content.append( '<p>' + feed.description + '</p>' );
              }
           );
         }
     });
 }

HTML

<div>
   <select id=feedSelect onchange="load_feed(this,'feedDiv');" >
      <option value='url-to-first-feed' text='First Feed' selected=true />
      <option value='url-to-second-feed' text='Second Feed' />
      ...
   </select>
   <div id='feedDiv'>
   </div>
</div>
盛夏尉蓝 2024-07-15 07:21:08

这并不完全相同,但它使用简单的 CSS 和 HTML,不需要 Javascript。
一些逆向工程可以大有帮助。

Image_switcher

它是荷兰语,但很简单:将鼠标移到 部件和图像开关。

纯CSS+HTML,无Javascript

It's not exactly the same thing, but this uses simple CSS and HTML and no Javascript needed.
A bit of reverse engineering can go a long way.

Image_switcher

it's in dutch, but it's simple: move your mouse over the <a> parts and the image switches.

Pure CSS+HTML, no Javascript

野鹿林 2024-07-15 07:21:08

您有两个选择:

  1. 预加载所有 RSS 提要(我假设示例页面中的

      是 RSS 提要的 HTML 输出?)、隐藏加载文档时将它们全部显示出来,然后将它们显示为选定的

  2. 在选择框更改时使用 AJAX 动态抓取所选的提要信息。

下面是执行前者的 javascript 和 jQuery 版本的简单示例:

html:

<select id="showRss">
   <option name="feed1">Feed 1</option>
   <option name="feed2">Feed 2</option>
</select>

<div id="rssContainer">
   <ul id="feed1">
      <li>feed item 1</li>
      <li>...</li>
   </ul>
   <ul id="feed2">
      <li>feed item 2</li>
      <li>...</li>
   </ul>
   <!-- etc... -->
</div>

javascript:

var rss = document.getElementById('rssContainer'); // main container
var nodes = rss.getElementsByTagName('ul');        // collection of ul nodes
var select = document.getElementById('showRss');   // your select box

function hideAll()  {                              // hide all ul's
    for (i = 0; i < nodes.length; ++i)  {
        nodes[i].style.display = 'none';
    }
}

select.onchange = function()    {                  // use the 'name' of each
    hideAll();                                     // option as the id of the ul
    var e = this[this.selectedIndex].getAttribute('name');
    var show = document.getElementById(e);         // to show when selected
    show.style.display = 'block';
}

hideAll();

jQuery:

$('#showRss').change(function() {
    $('#rssContainer ul').hide('slow');            // added a bit of animation
    var e = '#' + $(':selected', $(this)).attr('name');
    $(e).show('slow');                             // while we change the feed
});

$('#rssContainer ul').hide();

要执行选项 2,您的 onchange 函数将处理 AJAX 加载。 如果您不太熟悉 AJAX,并且有一些提要,那么选项 1 可能是最简单的。 (再次,我假设您已经将 RSS 解析为 HTML,因为这完全是另一个主题)。

you have two options:

  1. pre-load all the rss feeds (i'm assuming your <ul>'s in your example page are the HTML output of your RSS feeds?), hide them all when your document loads, and then reveal them as selected

  2. use AJAX to dynamically grab the selected feed information as your select box changes.

here's a quick example of a javascript and jQuery version of doing the former:

html:

<select id="showRss">
   <option name="feed1">Feed 1</option>
   <option name="feed2">Feed 2</option>
</select>

<div id="rssContainer">
   <ul id="feed1">
      <li>feed item 1</li>
      <li>...</li>
   </ul>
   <ul id="feed2">
      <li>feed item 2</li>
      <li>...</li>
   </ul>
   <!-- etc... -->
</div>

javascript:

var rss = document.getElementById('rssContainer'); // main container
var nodes = rss.getElementsByTagName('ul');        // collection of ul nodes
var select = document.getElementById('showRss');   // your select box

function hideAll()  {                              // hide all ul's
    for (i = 0; i < nodes.length; ++i)  {
        nodes[i].style.display = 'none';
    }
}

select.onchange = function()    {                  // use the 'name' of each
    hideAll();                                     // option as the id of the ul
    var e = this[this.selectedIndex].getAttribute('name');
    var show = document.getElementById(e);         // to show when selected
    show.style.display = 'block';
}

hideAll();

jQuery:

$('#showRss').change(function() {
    $('#rssContainer ul').hide('slow');            // added a bit of animation
    var e = '#' + $(':selected', $(this)).attr('name');
    $(e).show('slow');                             // while we change the feed
});

$('#rssContainer ul').hide();

to do option 2, your onchange function would handle the AJAX loading. if you're not that familiar with AJAX, and have a few feeds, option 1 is probably the easiest. (again, i'm assuming you have already parsed out your RSS as HTML, as that's another topic altogether).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文