When I click on a button i want to be able to jump down or scroll to a specific div or target on the page.
$('#clickMe').click(function() {
//jump to certain position or div or #target on the page
});
How can I do this?
解决方案
I would style a link to look like a button, because that way there is a no-js fallback.
So this is how you could animate the jump using jquery. No-js fallback is a normal jump without animation.
Original example:
$(document).ready(function() {
$(".jumper").on("click", function( e ) {
e.preventDefault();
$("body, html").animate({
scrollTop: $( $(this).attr('href') ).offset().top
}, 600);
});
});
#long {
height: 500px;
background-color: blue;
}
Pliip
Ploop
...
pliip
ploop
New example with actual button styles for the links, just to prove a point.
Everything is essentially the same, except that I changed the class .jumper to .button and I added css styling to make the links look like buttons.
jquery link jquery linkbutton自动跳转 位置
转载文章标签 jquery link jq 在页面某个位置触发点击 css 解决方案 html 文章分类 jQuery 前端开发