您需要哪些文件来完成这个jQuery UI Menus示例?

huangapple go评论54阅读模式
英文:

What files do I need for this jQuery UI Menus example?

问题

以下是您提供的内容的翻译部分:

我试图在本地使此示例工作(以便我可以修改以适应自己的需求),但鉴于糟糕的结果,我猜测缺少重要的东西:

https://codepen.io/seungjaeryanlee/pen/YYoGbp

我假设它需要jQuery和jQuery UI文件,我已经包含了它们,但它根本不起作用。我只得到了一个格式不正确的页面,没有菜单功能的迹象。

示例在上面的链接上正常工作,但不清楚我是否需要其他东西。

我需要包含其他东西吗?

我的版本如下(为了简单起见,放在一个文件中):

以上为翻译好的部分,不包括代码部分。

英文:

I'm trying to get this example working locally (so I can modify for my own use), but given the poor result I'm guessing that something significant is missing:

https://codepen.io/seungjaeryanlee/pen/YYoGbp

I assume it needs jQuery and jQuery UI files, and I've included those but it's not working at all. I just get a badly formed page with no sign of menu functionality.

The example works ok at the link above, but isn't clear what else I need.

Do I need to include something else?

My version follows (in 1 file for simplicity):

<html>
	<head>
		<style>
			#menubar {
				position: fixed;
				top: 0;
				left: 0;
				width: 100%;
			}

			/* Make jQuery UI Menu into a horizontal menubar with vertical dropdown */
			#menubar > li { /* Menubar buttons */
				display: inline-block;
			}
			#menubar > li > ul > li { /* Menubar buttons inside dropdown */
				display: block;
			}

			/* Change dropdown carets to correct direction */
			#menubar > li > div > span.ui-icon-caret-1-e {
				/* Caret on menubar */
				background:url(https://www.drupal.org/files/issues/ui-icons-222222-256x240.png) no-repeat -64px -16px !important;
			}
			#menubar ul li div span.ui-icon-caret-1-e {
				/* Caret on dropdowns */
				background:url(https://www.drupal.org/files/issues/ui-icons-222222-256x240.png) no-repeat -32px -16px !important;
			}
		</style>
    
		<script type="text/javascript" src = "https://code.jquery.com/jquery-1.10.2.js"></script>
		<script type="text/javascript" src = "https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

		<script>
			$(document).ready(function() {
				$('#menubar').menu();
				
				$('#menubar').menu({
					position: { my: 'left top', at: 'left bottom' },
					blur: function() {
					$(this).menu('option', 'position', { my: 'left top', at: 'left bottom' });
					},
					focus: function(e, ui) {
					if ($('#menubar').get(0) !== $(ui).get(0).item.parent().get(0)) {
						$(this).menu('option', 'position', { my: 'left top', at: 'right top' });
					}
					},
				});
			});
		</script>
	</head>

	<body>
		<ul id="menubar">
			<li><div>Alpha</div></li>
			<li>
				<div>Beta</div>
				<ul>
				<li><div>Beta 1</div></li>
				<li>
					<div>Beta 2</div>
					<ul>
					<li><div>Beta 2a</div></li>
					<li><div>Beta 2b</div></li>
					</ul>
				</li>
				<li><div>Beta 3</div></li>
				</ul>
			</li>
			<li><div>Gamma</div></li>
			<li><div>Delta</div></li>
			</ul>
	</body>

</html>

答案1

得分: 2

以下是您要翻译的内容:

Appears to work as expected when you have all the CSS and JS files.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

$(function() {
  $('#menubar').menu({
    position: {
      my: 'left top',
      at: 'left bottom'
    },
    blur: function() {
      $(this).menu('option', 'position', {
        my: 'left top',
        at: 'left bottom'
      });
    },
    focus: function(e, ui) {
      if ($('#menubar').get(0) !== $(ui).get(0).item.parent().get(0)) {
        $(this).menu('option', 'position', {
          my: 'left top',
          at: 'right top'
        });
      }
    },
  });
});

<!-- language: lang-css -->

#menubar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
}

/* Make jQuery UI Menu into a horizontal menubar with vertical dropdown */

#menubar>li {
  /* Menubar buttons */
  display: inline-block;
}

#menubar>li>ul>li {
  /* Menubar buttons inside dropdown */
  display: block;
}

/* Change dropdown carets to correct direction */

#menubar>li>div>span.ui-icon-caret-1-e {
  /* Caret on menubar */
  background: url(https://www.drupal.org/files/issues/ui-icons-222222-256x240.png) no-repeat -64px -16px !important;
}

#menubar ul li div span.ui-icon-caret-1-e {
  /* Caret on dropdowns */
  background: url(https://www.drupal.org/files/issues/ui-icons-222222-256x240.png) no-repeat -32px -16px !important;
}

<!-- language: lang-html -->

<link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script>
<ul id="menubar">
  <li>
    <div>Alpha</div>
  </li>
  <li>
    <div>Beta</div>
    <ul>
      <li>
        <div>Beta 1</div>
      </li>
      <li>
        <div>Beta 2</div>
        <ul>
          <li>
            <div>Beta 2a</div>
          </li>
          <li>
            <div>Beta 2b</div>
          </li>
        </ul>
      </li>
      <li>
        <div>Beta 3</div>
      </li>
    </ul>
  </li>
  <li>
    <div>Gamma</div>
  </li>
  <li>
    <div>Delta</div>
  </li>
</ul>

<!-- end snippet -->
英文:

Appears to work as expected when you have all the CSS and JS files.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

$(function() {
  $(&#39;#menubar&#39;).menu({
    position: {
      my: &#39;left top&#39;,
      at: &#39;left bottom&#39;
    },
    blur: function() {
      $(this).menu(&#39;option&#39;, &#39;position&#39;, {
        my: &#39;left top&#39;,
        at: &#39;left bottom&#39;
      });
    },
    focus: function(e, ui) {
      if ($(&#39;#menubar&#39;).get(0) !== $(ui).get(0).item.parent().get(0)) {
        $(this).menu(&#39;option&#39;, &#39;position&#39;, {
          my: &#39;left top&#39;,
          at: &#39;right top&#39;
        });
      }
    },
  });
});

<!-- language: lang-css -->

#menubar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
}

/* Make jQuery UI Menu into a horizontal menubar with vertical dropdown */

#menubar&gt;li {
  /* Menubar buttons */
  display: inline-block;
}

#menubar&gt;li&gt;ul&gt;li {
  /* Menubar buttons inside dropdown */
  display: block;
}


/* Change dropdown carets to correct direction */

#menubar&gt;li&gt;div&gt;span.ui-icon-caret-1-e {
  /* Caret on menubar */
  background: url(https://www.drupal.org/files/issues/ui-icons-222222-256x240.png) no-repeat -64px -16px !important;
}

#menubar ul li div span.ui-icon-caret-1-e {
  /* Caret on dropdowns */
  background: url(https://www.drupal.org/files/issues/ui-icons-222222-256x240.png) no-repeat -32px -16px !important;
}

<!-- language: lang-html -->

&lt;link rel=&quot;stylesheet&quot; href=&quot;//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css&quot;&gt;
&lt;script src=&quot;https://code.jquery.com/jquery-3.6.0.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://code.jquery.com/ui/1.13.2/jquery-ui.js&quot;&gt;&lt;/script&gt;
&lt;ul id=&quot;menubar&quot;&gt;
  &lt;li&gt;
    &lt;div&gt;Alpha&lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;div&gt;Beta&lt;/div&gt;
    &lt;ul&gt;
      &lt;li&gt;
        &lt;div&gt;Beta 1&lt;/div&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;div&gt;Beta 2&lt;/div&gt;
        &lt;ul&gt;
          &lt;li&gt;
            &lt;div&gt;Beta 2a&lt;/div&gt;
          &lt;/li&gt;
          &lt;li&gt;
            &lt;div&gt;Beta 2b&lt;/div&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;div&gt;Beta 3&lt;/div&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;div&gt;Gamma&lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;div&gt;Delta&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年7月7日 01:03:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76631085.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定