You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
767 B
JavaScript

(function($){
$.fn.mAnchor = function(options){
var defaults = {
ieFreshFix: true,
anchorSmooth: true,
anchortag: "anchor",
animateTime: 1000
};
var sets = $.extend({}, defaults, options || {});
//IE BUG
if(sets.ieFreshFix){
var url = window.location.toString();
var id = url.split("#")[1];
if(id){
var t = $("#"+id).offset().top;
$(window).scrollTop(t);
}
}
//A
$(this).each(function(){
$(this).click(function(){
var aim = $(this).attr(sets.anchortag).replace(/#/g,""); //id
var pos = $("#"+aim).offset().top;
if(sets.anchorSmooth){
$("html,body").animate({scrollTop: pos}, sets.animateTime);
}else{
$(window).scrollTop(pos);
}
return false;
});
});
};
})(jQuery);