- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含很多内容的单页网站,左侧有一个粘性侧边栏导航。 I am trying to get the page to scroll down to the corresponding section in the contents div whenever a menu item is selected.这可能是非常基本的东西,但我就是无法理解它(一直在尝试各种解决方案,但没有成功——见下面的代码)。
我对 javascript 和 jquery 比较陌生,非常感谢您的想法/建议。
到目前为止我设法做了什么:
现在所缺少的只是菜单链接的工作以及实际将页面下推到正确的部分 ID。
再次抱歉,如果这是一个非常愚蠢的问题,我非常感谢您提出任何建议。
$(function() {
$('.feature_tab').click(function(evt) {
var selectedTab = $(this);
var featureGroup = selectedTab.parents('.features_public_content_container');
var allTabs = featureGroup.find('.feature_tab');
var allContent = featureGroup.find('.feature_box');
// get the rel attribute to know what box we need to activate
var rel = $(this).attr('rel');
// clear tab selections
allTabs.removeClass('selected');
selectedTab.addClass('selected');
// make all boxes "in-active"
$('.feature_box').each(function() {
$(this).removeClass('active');
});
//show what we need
$('.feature_box.feature_category_'+rel).addClass('active');
// find correlated content
var idx = selectedTab.index();
var selectedContent = $(allContent);
selectedContent.removeClass('in-active');
$('a').click(function(){
$('html, body').animate({
scrollTop: $( $(this).attr('href') ).offset().top
}, 1000);
return false;
});
});
});
.hidden {
display:block;
color: blue;
}
.features_page {
margin-top:65px;
position: relative;
}
.features_public_content_container {
width:100%;
height: 100% !important;
position: relative;
max-width:1200px;
margin-left:auto;
margin-right:auto;
font-size:12px;
padding:0 40px
}
#left_sidebar {
height: 100% !important;
width: 20%;
border: 4px solid green !important;
position: absolute;
float: left
}
#right {
border: 4px solid pink !important;
height: auto;
max-width:80%;
top: 0;
right: 0;
float: right;
position: relative;
}
.features_page .sidebar_nav_container {
margin:45px auto;
background: yellow;
position: relative;
float: left
}
.features_page .sidebar_nav_container .feature_tab {
float:none;
width:100%;
color:#1193f6 !important;
text-align: left;
line-height:40px;
height:40px;
padding-left: 24px;
font-size:12px;
border-left:1px solid #efefef !important;
text-transform:uppercase;
font-weight:500;
overflow:hidden;
cursor:pointer;
position:relative
}
.features_page .sidebar_nav_container .feature_tab .indicator {
position:absolute;
width:100%;
height: 100%;
display:none;
bottom:0;
left: 0
}
.features_page .sidebar_nav_container .feature_tab:hover .indicator {
display:block;
border-left:4px solid #d6ecfd
}
.features_page .sidebar_nav_container .feature_tab.selected .indicator {
display:block;
border-left:4px solid #1193f6;
}
.features_page .feature_boxes_container {
padding-bottom:80px;
padding-top:45px;
text-align: center;
background: #f2f2f2;
}
.features_page .feature_boxes_container .feature_box {
background:#fff;
display:inline-block;
height:210px;
width:235px;
margin:12px;
padding: 24px;
text-align:center;
vertical-align:top;
-webkit-border-radius:2px;
-moz-border-radius:2px;
-ms-border-radius:2px;
-o-border-radius:2px;
border-radius:2px;
-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.12);
-moz-box-shadow:0 1px 3px rgba(0,0,0,0.12);
-ms-box-shadow:0 1px 3px rgba(0,0,0,0.12);
-o-box-shadow:0 1px 3px rgba(0,0,0,0.12);
box-shadow:0 1px 3px rgba(0,0,0,0.12)
}
.features_page .feature_boxes_container .feature_box.active {
border: 2px solid #1193f6;
}
.features_page .feature_boxes_container .feature_box .feature_overview_icon {
padding: 18px
}
.features_page .feature_boxes_container .feature_box.active .feature_overview_icon {
color: #1193f6;
}
.features_page .feature_boxes_container .feature_box.in-active .feature_overview_icon {
color: #363636;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<body id='public_layout' class='with_header'>
<div class="layout_wrapper">
<div class="features_page">
<div class="container features_public_content_container">
<div class="col span_2" id="left_sidebar">
<div class="sidebar_nav_container">
<div class="feature_tab indicator feature_category_A selected" rel="A"><a href="#A">Features A</a></div>
<div class="feature_tab indicator feature_category_B" rel="B"><a href="#B">Features B</a></div>
<div class="feature_tab indicator feature_category_C" rel="C"><a href="#C">Features C</a></div>
<div class="feature_tab indicator feature_category_D" rel="D"><a href="#D">Features D</a></div>
<div class="feature_tab indicator feature_category_E" rel="E"><a href="#E">Features E</a></div>
</div>
</div> <!-- / sidebar navigation -->
<div class="col span_10" id="right">
<div class="feature_boxes_container">
<div id="A"> <!-- START A Features -->
<div class="feature_box feature_category_A active">Feature A-1</div>
<div class="feature_box feature_category_A active">Feature A-2</div>
<div class="feature_box feature_category_A active">Feature A-3</div>
</div>
<div id="B"> <!-- START B Features -->
<div class="feature_box feature_category_B in-active">Feature B-1</div>
<div class="feature_box feature_category_B in-active">Feature B-2</div>
<div class="feature_box feature_category_B in-active">Feature B-3</div>
</div>
<div id="C"> <!-- START C Features -->
<div class="feature_box feature_category_C in-active">Feature C-1</div>
<div class="feature_box feature_category_C in-active">Feature C-2</div>
<div class="feature_box feature_category_C in-active">Feature C-3</div>
</div>
</div> <!-- /.feature_boxes_container -->
</div> <!-- /.col .span_10 -->
</div> <!-- /.public_content_container -->
</div> <!-- /.features_page -->
</div> <!-- /.layout_wrapper -->
</body>
</html>
最佳答案
可能你想要这个:
$('a').click(function(){
$('html, body').animate({
scrollTop: $( $(this).attr('href') ).offset().top
}, 500);
return false;
});
另请参阅这些问题:
Simple jQuery scroll to anchor up or down the page...?
Smooth scrolling when clicking an anchor link
你也可以使用插件来做到这一点。喜欢 FullPage
关于javascript - 单页网站上的侧边栏菜单不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35308174/
我有一个单页应用程序。单击导航链接时,有一个脚本会向下滚动到适当的部分。这工作正常。 $('nav a').click(function(){ $('html, body').animate(
如今,有许多很酷的工具可用于创建功能强大的“单页” JavaScript网站。在我看来,这是通过让服务器充当API(仅此而已)和让客户端处理所有HTML生成内容来正确完成的。这种“模式”的问题是缺乏搜
我正在尝试创建一个页面,滚动站点包含一组图像和相应的标题。我想将标题固定在页面底部。我想解决方案将涉及为每个图像分配一个 id,当它位于距窗口顶部一定距离内时将触发隐藏/显示事件。在 this exa
我在一个页面上有两个表单:登录表单和注册表单。当我提交注册表单时,它会验证以下两项:登录和注册中的表单字段。如果两个表单具有相同的模型(用户模型),我该如何处理 登记表 Form->create('U
我正在寻求帮助来自动化我的单页 Angular 应用程序的性能测试。我们正在使用 Protractor 进行 E2E 测试,并希望添加性能测试。我们的第一个目标是能够测量例如之间的简单时间。按钮单击并
我正在创建单页 Web 应用程序。 我为应用程序结构创建了一个基本设计。 This回答关于 this视频非常有帮助。 该应用程序包含一个 html 页面。 JS代码将改变它的内容。Usher 将根据
我只是想知道在不使用 ember js/angular js 等框架的情况下使用 javascript 创建单页网站的技术是什么。 例如在php中他们可以得到 example.com?view=hom
我刚刚读到有关公开用于检索数据的 RESTful 接口(interface)的单页 Web 应用程序 - 例如以 JSON 格式,并且只提供一个引用负责调用 RESTful 接口(interface)
我的单页框内容没有像我希望的那样响应迅速。当我尝试阅读以下页面时:https://institutoschuman.org/en/the-monographies/使用我的手机,右侧的文字被裁剪了。看
我正在构建我的第一个 WebApp。我的头部有一个小导航栏,其中应该放置后退按钮。应用程序的页面全部放置在一个文档中,因此 div 设置为 并且将通过点击链接来显示 onclick="show('P
好吧,这个问题我们都看过一百万次了,但我正在寻找更新的答案。 我们如何在安装 Wordpress 时使用 SSL 加密单个页面?更进一步,我们如何使该单个页面通过 SSL 与服务器通信? 注意:您不能
我有一个单页 Wordpress 站点,它从其他帖子获取主页上的所有内容。我安装了 yoast 插件,但我想知道我是在每个帖子上输入关键字并放置 301 重定向,以便当它出现时它只转到主页,还是我不索
我们需要将现有的一系列页面/工作流屏幕更改/重写为一个标准页面。该项目本身本质上是在一个更大的现有应用程序的上下文中构建一个单一的网页应用程序。 我们的目标是尽可能让服务器端实现保持原样。这意味着我们
我正计划为 Wordpress 主题制作一个模板页面,它将在页面的内容部分加载 5 个单独的“模块”。这些模块旨在分别显示不同类别的最新 4 篇帖子(工作方式与 this 类似)。 在循环中处理此问题
情况 我正在制作一个包含多个页面的 Web 应用程序原型(prototype),其中一些页面有大量的 JavaScript 负载。我有一个(不是很原始的)想法,让页面布局加载一次,并且只用 ajax
我想创建一个网页。我需要的是网页的大小应该根据用户窗口的大小而定,就像我们不需要向下滚动就可以看到某些东西一样。我可以将它更改为特定高度,但问题是在调整浏览器窗口大小时,它再次包含滚动选项,因为图像大
我需要设置 Magento 的订单成功页面 /checkout/onepage/success/ 的样式,但因为它在没有订单 session 时重定向,所以我无法刷新页面来检查我的更改! 有人知道如何
如何为单页 JavaScript 应用程序生成唯一的 URL。 这些 URL 应该像普通 URL 一样运行,即将其粘贴到浏览器中,如果用户具有权限,应用程序应该加载显示的特定 View 。 Gmail
我用过 skipfish和 Burp Suite 之前在“标准”Web 应用程序上。 但是我现在写的越来越多single-page apps ,在我的例子中是 backbone.js。 有没有软件可以
与其在单个 dropzone 元素上上传多个文件,不如在一个页面上有多个 dropzone 元素? 当有多个元素时,似乎 dropzone 在选择对话框之后甚至没有触发,每个元素都有自己的 dropz
我是一名优秀的程序员,十分优秀!