我正在寻找一种方法,当你在页面上或下点击一个指向本地锚的链接时,加入一个幻灯片效果.
我想要一些你有这样一个链接的东西:
<a href="#nameofdivetc">link text, img etc.</a>
可能添加了一个类,这样您就知道希望此链接成为滑动链接:
<a href="#nameofdivetc" class="sliding-link">link text, img etc.</a>
然后,如果单击此链接,页面会向上或向下滑动到所需的位置(可以是div、heading、页面顶部等).
这就是我之前所说的:
$(document).ready(function(){
$(".scroll").click(function(event){
//prevent the default action for the click event
event.preventDefault();
//get the full url - like mysitecom/index.htm#home
var full_url = this.href;
//split the url by # and get the anchor target name - home in mysitecom/index.htm#home
var parts = full_url.split("#");
var trgt = parts[1];
//get the top offset of the target anchor
var target_offset = $("#"+trgt).offset();
var target_top = target_offset.top;
//goto that anchor by setting the body scroll top to anchor top
$('html, body').animate({scrollTop:target_top}, 1500, 'easeInSine');
});
});