- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的网站上使用 ajax 来动态加载页面并向 url 添加哈希值以保留历史记录和浏览器后退按钮,为此我使用了基于 html5 的
,我不得不说除了一个问题之外一切正常,那就是当前链接的事件类。jquery bbq
插件history api
我有两个导航主菜单,它只在主页上,第二个包含在每个页面上,具有 php include
功能及其主菜单的子导航.
正如我所说,我的问题是如何将事件类添加到任何被点击的链接,使其看起来与其他链接不同,用户应该知道他们现在在哪里!
我尝试了不同的技术,但那些只适用于 main menu
和 secondary nav
的一些问题为了更好地理解请看这个 video
正如您在视频中看到的那样,它在 主菜单
上运行良好,但仅在单击任何链接一次后将类添加到 secondary menu
然后单击另一个链接,然后单击返回原始链接,此外,当我刷新它时,它会删除事件类。
这是我的代码。
主菜单
<div id="vertical-menu">
<!--<h2 class="logo">LOGO</h2>-->
<div class="logo">
<span class="arcd-male97"></span>
<h2 class="logo-name">AMR</h2>
<h6 class="logo-desc">ARCADE MUSIC REPOSITORY</h6>
</div>
<nav>
<ul id='menu' class="menu-items">
<li><a href="#Browse/Browse_Page0.php"><i class="arcd-archive"></i></br>Browse</a></li>
<li><a href="#Top_albums/Top_albums_Page0.php"><i class="arcd-music97"></i></br>Top albums</a></li>
<li><a href="#Top_artists/Top_artists_Page0.php" ><i class="arcd-microphone52"></i></br>Top artists</a></li>
<li><a href="#Top_lists/Top_lists_Page0.php" ><i class="arcd-numbered8"></i></br>Top lists</a></li>
<li><a href="#Charts/Charts_Page0.php" ><i class="arcd-rising9"></i></br>Charts</a></li>
</ul>
</nav>
</div>
二级导航栏
<div class="header_container" id="header_container"> <!--start header div-->
<div id="header_titles">
<h1 class="browse-heading">BROWSE</h1>
<h2 class="browse-subheading">GENRES & MOODS</h2>
</div>
</div> <!--end header div-->
<div id="tabnav_container"> <!--start tabnav_container-->
<div class="navtab_background"></div>
<nav>
<ul id="tabnav">
<li class="pop_tab"><a href="#Browse/Browse_Page1.php"><i class="arcd-microphone352"></i>pop</a></li>
<li class="country_tab"><a href="#Browse/Browse_Page2.php"><i class="arcd-guitarcountry"></i>country</a></li>
<li class="rock_tab"><a href="#Browse/Browse_Page3.php"><i class="arcd-electricclone"></i>rock</a></li>
<li class="blues_tab"><a href="#Browse/Browse_Page4.php"><i class="arcd-harmonicblues"></i>blues</a></li>
<li class="edm_tab"><a href="#Browse/Browse_Page5.php"><i class="arcd-disc62edm"></i>edm</a></li>
<li class="jazz_tab"><a href="#Browse/Browse_Page6.php"><i class="arcd-trumpet12jazz"></i>jazz</a></li>
<li class="rnb_tab"><a href="#Browse/Browse_Page7.php"><i class="arcd-mic102"></i>r&b</a></li>
<li class="hip-hop_tab"><a href="#Browse/Browse_Page8.php"><i class="arcd-musicplayer1hiphop"></i>hip hop</a></li>
<li class="reggae_tab"><a href="#Browse/Browse_Page9.php"><i class="arcd-mic102"></i>reggae</a></li>
<li class="classical_tab"><a href="#Browse/Browse_Page10.php"><i class="arcd-violin62classical"></i>classical</a></li>
<li class="folk_tab"><a href="#Browse/Browse_Page11.php"><i class="arcd-guitar92folk"></i>folk</a></li>
<li class="soul_tab"><a href="#Browse/Browse_Page12.php"><i class="arcd-mic102"></i>soul</a></li>
</ul>
</nav>
</div><!--end tabnav_container-->
这是ajax脚本
$(function() {
// Keep a mapping of url-to-container for caching purposes.
var cache = {
// If url is '' (no fragment), display this div's content.
'': $('#default-homepage-contents')
};
// Bind an event to window.onhashchange that, when the history state changes,
// gets the url from the hash and displays either our cached content or fetches
// new content to be displayed.
$(window).bind( 'hashchange', function(e) {
// Get the hash (fragment) as a string, with any leading # removed. Note that
// in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
var url = $.param.fragment();
// Hide any visible ajax content.
$( '#main-container' ).children( ':visible' ).hide();
if ( cache[ url ] ) {
// Since the element is already in the cache, it doesn't need to be
// created, so instead of creating it again, let's just show it!
cache[ url ].fadeIn(1000);
} else {
// Show "loading" content while AJAX content loads.
$( '#loading' ).delay(500).show();
// Create container for this url's content and store a reference to it in
// the cache.
cache[ url ] = $( '<div class="bbq-item"/>' )
// Append the content container to the parent container.
.appendTo( '#main-container' )
// Load external content via AJAX. Note that in order to keep this
// example streamlined, only the content in .infobox is shown. You'll
// want to change this based on your needs.
.load( url, function() {
// Content loaded, hide "loading" content.
$( '#loading' ).fadeOut(1000);
});
}
})
// Since the event is only triggered when the hash changes, we need to trigger
// the event now, to handle the hash the page may have loaded with.
$(window).trigger( 'hashchange' );
});
感谢您的帮助!
最佳答案
我在使用新浏览器时遇到问题并发现了这个,我认为唯一正确工作的插件:jquery address和文档在这里:http://www.asual.com/jquery/address/docs/#api-reference示例用法是
$(function() {
//push it to history
$('#tabnav > li').click(function(e) {
e.preventDefault();
$.address.parameter("browse", $(this).attr("href"), false);
});
//catch changes
$.address.change(function () {
$.each($.address.parameterNames(), function (index, value) {
url = $.address.parameter(value);
$('a[href="'+url+'"]').addClass('active');
});
});
});
关于javascript - 我正在努力使用 ajax 将事件类添加到我的导航菜单中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31818618/
我为我的一些问题设置了标签。当搜索 labels="ab"时,我得到了相关的标签,但我似乎找不到询问标签的正确语法!="ab"。如何查询不等于ab的? 最佳答案 != 对我有用,尽管它只显示带有标签的
我最近使用 Visual Studio 2013 Express 配置了 GITHUB 和 Demo GITHub 帐户,即用于练习目的。 Good News is that : I have con
我有一个用于播放和暂停的切换按钮。 这是代码: export default (props) => { let [soundState, setSoundState] = useState({ s
一个 XML 文件被发布到我的 spring mvc 正在响应的 URL。 在 .NET 中,我可以这样做: request.Form[0] request.Form["abc"] 或 request
我们的监控脚本遇到问题。 程序流程为 客户将文件(.csv 格式)ftp/sftp 到“源”目录 Bash 脚本将完成的 .csv 文件重命名为 .aaa 文件 另一个 Bash 脚本将“.aaa”文
如果我开始一个线程: new Thread(() -> { while (running) { try { Thread.sl
我正在制作一个看起来像真正的书的 PDF 阅读器。 我在 ScrollView 中有一个 UIImageView 作为书的背景(想象一本打开的书,有空页)。 UIImageView 的层有 2 个子层
创建 Accordion - 在幻灯片上 - 正在滑动的元素下方的元素似乎向下移动了 px,然后又向上移动,从而产生了颤动效果。 $(document).ready(function() { //Pr
我有一个非常奇怪的问题,但只有在运行 Ubuntu 时才会出现(在 CentOS 上一切正常)。我用 Perl 编写了一个脚本并使用了 Mail::IMAPClient模块。 当我运行以下命令时: p
我知道我可以检查 UITextView 是否正在使用 textViewDidBeginEditing: 进行编辑,但我想检查它是否正在使用 if 语句进行编辑? 最佳答案 使用方法isFirstRes
我正在制作一个简单的点击器类型的游戏。问题是,我的 JPanel 忽略了我设置为每秒更新的 Swing 计时器,而是每毫秒更新一次,即使我删除了计时器也是如此。除了计时器的监听器之外,不会在任何地方调
我有以下代码,应该通过组织列表对每个组织进行 td,对每个组织调用 toString 方法,并将结果打印到控制台和名为 Debug1.tab 的文件。 try { StreamWriter p
我有以下代码用于将文件从 url 下载到 sdcard 。此代码适用于小文件,但当文件大时,我下载的文件大小为 0。任何帮助将不胜感激。 Java 代码 setContentView(R.layout
我有一个必须使用 tomcat 部署的 Angular 项目。 Angular 文件在 dist/project-ui/ 中构建文件夹。我复制了 project-ui文件夹到 webapps tomc
我有一堆切换按钮,下面有标签。如果按钮的标签变得太长,那么下一行的第一个按钮将卡在该标签上。 这是我的代码: https://jsfiddle.net/Android272/c150305z/ 我查了
具有特殊字符的 InnerHTML 正在 trim 数据。 elem.innerHTML = displayedObjects.name; 这里的 displayedObjects.name 包含一个
我已经成功地设置了我的证书和 key ,并使用了在这里找到的 mysql 文档: http://dev.mysql.com/doc/refman/5.1/en/replication-solution
在为游戏制作动画和更新计时器时,我读到任何与 GUI 相关的 Activity 都应该在 EDT 上运行,包括重新绘制屏幕。我正在使用单个 ScheduledExecutorService 来更新和绘
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Large numbers erroneously rounded in Javascript 我正在使用
我已经为 .NET RyuJit 安装了新的 Jit 编译器,并按照安装文档中的说明在 regedit 的 .NetFramework 中设置了 AltJit=* 键。 http://blogs.ms
我是一名优秀的程序员,十分优秀!