правильно задать условие
Посоветуйте что можно сделать с якорем, скрипт выглядит так :
//scroll var theDestinations = $('a[id]'); theDestinations.each(function(i){ var thisDestination = $(this), thisDestinationOffset = thisDestination.offset(), thisLink = $("a[href='/#" + thisDestination.attr("id") + "']"); if(thisLink.length > 0) { thisLink.click(function(){ $('html,body').animate({scrollTop : thisDestinationOffset.top-10}, 1500); return false; }); } }); 2 3 thisLink = $("a[href='/#" + thisDestination.attr("id") + "']"); // В этой строке слеш перед решёткой чтобы с других разделов сайта на главную ссылалось нормально.. Но проблема когда с главной пробую ссылатся на якорь он его невидит едит до конца страницы. На главной должно быть без слеша, но скрипт под слеш заточен, как быть?) так постоянно перезагружается браузер if(location.href="http://testsite.ru/"){ var theDestinations = $('a[id]'); theDestinations.each(function(i){ var thisDestination = $(this), thisDestinationOffset = thisDestination.offset(), thisLink = $("a[href='#" + thisDestination.attr("id") + "']"); if(thisLink.length > 0) { thisLink.click(function(){ $('html,body').animate({scrollTop : thisDestinationOffset.top-10}, 1500); return false; }); } }); } else { var theDestinations = $('a[id]'); theDestinations.each(function(i){ var thisDestination = $(this), thisDestinationOffset = thisDestination.offset(), thisLink = $("a[href='/#" + thisDestination.attr("id") + "']"); if(thisLink.length > 0) { thisLink.click(function(){ $('html,body').animate({scrollTop : thisDestinationOffset.top-10}, 1500); return false; }); } }); } |
Часовой пояс GMT +3, время: 11:44. |