点击切换按钮时向下移动窗口视点
Move windows viewpoint down when clicking on toggle
单击more按钮时,将显示其余文本。对于较小的屏幕,我们需要向下滚动以阅读所有文本。当点击更多的切换时,是否有办法将视点向下移动几个像素?我希望点击更多后,它能滑到文章的标题。我在文章包装的顶部有边距,不想删除它。
$(document).ready(function() {
var ellipsestext = "...",
moretext = "More",
lesstext = "Less",
showChar;
$('.more').each(function() {
var content = $(this).html();
showChar = content.search(/<!'-'-'s*break's*'-'->/);
if (content.length > showChar && showChar != -1) {
var c = content.substr(0, showChar);
var h = content.substr(showChar, content.length - showChar);
var html = c + '<span class="moreellipses">' + ellipsestext + ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>';
$(this).html(html);
}
});
$(".morelink").click(function() {
if ($(this).hasClass("less")) {
$(this).removeClass("less");
$(this).html(moretext);
} else {
$(this).addClass("less");
$(this).html(lesstext);
}
$(this).parent().prev().toggle();
$(this).prev().toggle();
return false;
});
});
#first article {
color: #FFFFFF;
background-color: rgba(14, 0, 0, 0.3);
width: 860px;;
float: right;
margin-bottom: 95px;
margin-top: 150px;
margin-left: auto;
margin-right: auto;
padding-right: 20px;
padding-bottom: 20px;
padding-left: 20px;
padding-top: 20px;
}
nav#menu {
position: fixed;
z-index: 5;
width: 100%;
top:0%;
text-align: center;
height: 90px;
box-shadow: 0 0 25px rgba(0,0,0,0.9);
background-color: rgba(14, 0, 0, 0.8);
}
nav#menu a {
text-decoration: none;
text-indent: -9999px;
color: #fff;
}
nav#menu li {
display:block;
font-size: 1.2em;
padding: 1em;
font-weight: 900;
font-family: 'Sorts Mill Goudy', serif;
text-align: center;
height: 3em;
display:table-cell;
vertical-align: middle;
/*border: solid 1px #fff;*/
}
nav#menu ul {
display: inline-block;
height: 85px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#7E7E7E7E', EndColorStr='#7E7E7E7E');*/
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<nav id="menu">
<ul>
<li><a class="first" href="#f">Home1</a></li>
<li><a class="first" href="#f">Home2</a></li>
</ul>
</nav>
<section id="first" class="story" data-speed="4" data-type="background" >
<div id="wrapper">
<article>
<div class="comment more">
<h2>Header</h2>
Son had talks with at least one lender before scrapping the plan at least three months ago when he could not agree with the overseas partner on financing conditions, the people said, asking not to be identified because they are not authorized to discuss the matter. <!-- break -->
While it was the top possible deal earlier this year, Son is no longer considering using that partner, the people said without elaborating.
Concerns about debt and struggling U.S. unit Sprint Corp. have driven SoftBank’s market value down to about $64 billion, or less than the stakes it holds in companies including Alibaba Group Holding Ltd. and Yahoo Japan Corp. A deal excluding Son’s 19.3 percent stake would be the biggest management buyout ever, according to data compiled by Bloomberg.
</div>
</article>
</div>
</section>
你可以使用scrollTop方法使用jQuery滚动。
// Example : Scroll the window at 450px from the top
$(window).scrollTop(450);
您可以在切换按钮的代码之后添加这一行(就在$(this).prev().toggle();
之后)。如果你改变了你的css或布局,你可能需要为scrollTop
使用一个不同的值。
如果你想滚动只有当你点击more
(而不是less
),你可以添加代码后,$(this).html(moretext);
相关文章:
- 如何打开/移动主屏幕左侧的浏览器窗口
- YouTube作为弹出窗口在桌面版本上播放,但不在移动设备上播放
- 将第二窗口移动到第二屏幕或特定屏幕
- 当移动地址栏出现/消失时,防止更改窗口高度
- 如何在缩放时获取移动浏览器窗口的宽度
- 如何在鼠标移动事件时更改图像的窗口中心和宽度
- 显示移动窗口时引导导航栏中的 atach 搜索栏
- 移动设备中的条纹支付弹出窗口
- 如何仅在窗口宽度从桌面(>1024px)更改为移动(<1025px)导航时重新加载页面
- 当窗口向上滚动时,如何使用粘性侧边栏向上移动
- jquery调整大小为移动窗口iPhone / Android
- 具有 100% 窗口高度的移动导航栏,无论内容如何
- javascript Y 滚动条在向下按钮的鼠标上移动,但窗口水平
- 使用 html/javascript 的 AIR 框架移动窗口
- 在移动屏幕中从纵向移动到横向并返回纵向时,窗口元素在垂直方向上变得不可见
- 如何使用 html 将 Windows 手机(但不是桌面窗口)重定向到移动网站
- Chrome 会在我移动窗口时隐藏我的窗口
- 在移动窗口上调整KineticJs画布的宽度大小事件
- 移动窗口时激活/停用事件
- 点击切换按钮时向下移动窗口视点